前提・実現したいこと
iced を用いて、macOSネイティブアプリの作り方を調査しています。
現在、文字列の配列を、画面上にTextとして表示しようとしています。
Column
を生成し、そこへ 複数の Text
を追加した後
into()
で表示したいのですが、コンパイルエラーとなっています。
コンパイルエラーの解消方法を教えていただけませんでしょうか?
発生している問題・エラーメッセージ
error[E0282]: type annotations needed --> src/main.rs:50:14 | 50 | *col.into() | ----^^^^-- | | | | | cannot infer type for type parameter `T` declared on the trait `Into` | this method call resolves to `T` | = note: type must be known at this point
該当のソースコード
rust
1use iced::{Settings, Application, Command, Clipboard, Element, Column, Text}; 2 3fn main() -> iced::Result { 4 TextViewer::run(Settings::default()) 5} 6 7#[derive(Debug, Clone)] 8struct TextViewer {} 9 10#[derive(Debug)] 11pub enum Message { 12 Loading, 13 Loaded, 14} 15 16impl Application for TextViewer { 17 type Executor = iced::executor::Default; 18 type Message = Message; 19 type Flags = (); 20 21 fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) { 22 (TextViewer{}, Command::none()) 23 } 24 25 fn title(&self) -> String { 26 String::from("Text を複数表示する実験") 27 } 28 29 fn update(&mut self, message: Self::Message, _clipboard: &mut Clipboard) -> Command<Self::Message> { 30 match message { 31 Message::Loading => {} 32 Message::Loaded => {} 33 } 34 Command::none() 35 } 36 37 fn view(&mut self) -> Element<'_, Self::Message> { 38 let listString = [String::from("ABC"), String::from("DEF")]; 39 let col = &Column::new(); 40 for s in listString.iter() { 41 col.push(Text::new(s)); 42 } 43 44 45 // 参照外ししない場合 46 // col.into() 47 // ^^^^ the trait `From<&iced_native::widget::column::Column<'_, _, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>>` is not implemented for `iced_native::element::Element<'_, Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>` 48 49 50 // 参照外しする場合 51 *col.into() 52// ----^^^^-- 53// | | | 54// | | cannot infer type for type parameter `T` declared on the trait `Into` 55// | this method call resolves to `T` 56 57 } 58}
試したこと
view
関数内部で Box
を利用してみましたが、同様のエラーが発生しました。
rust
1fn view(&mut self) -> Element<'_, Self::Message> { 2 let listString = [String::from("ABC"), String::from("DEF")]; 3 let col = Box::new(Column::new()); 4 for s in listString.iter() { 5 col.push(Text::new(s)); 6 } 7 8 *col.into() 9// ----^^^^-- 10// | | | 11// | | cannot infer type for type parameter `T` declared on the trait `Into` 12// | this method call resolves to `T` 13 }
補足情報(FW/ツールのバージョンなど)
OS
MacOS Big Sur 11.5.2(20G95)
Cargo.toml
[package] name = "RustWithCLion" version = "0.1.0" edition = "2018" publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] iced = { version = "0.3", features = ["async-std", "debug"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0"
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/09/23 08:47