loloof64

Untitled

Sep 30th, 2025
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 15.48 KB | None | 0 0
  1. (base) bordeaux80 :: Persos/Rust/skycrapers ‹master*› » cargo run
  2. warning: skycrapers v0.1.0 (/home/laurent/Documents/Programmation/Projets/Persos/Rust/skycrapers) ignoring invalid dependency `rfs` which is missing a lib target
  3.    Compiling skycrapers v0.1.0 (/home/laurent/Documents/Programmation/Projets/Persos/Rust/skycrapers)
  4. error[E0277]: the trait bound `Element<'_, _, _, _>: From<String>` is not satisfied
  5.   --> src/main.rs:145:20
  6.    |
  7. 145 |             button(t!("ui.toolbar.new_game").to_string()).on_press(Mess...
  8.    |             ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
  9.    |             |
  10.    |             required by a bound introduced by this call
  11.    |
  12.    = help: the trait `From<String>` is not implemented for `iced_core::element::Element<'_, _, _, _>`
  13.     = help: the following other types implement trait `From<T>`:
  14.               `iced_core::element::Element<'_, Link, Theme, Renderer>` implements `From<Rich<'_, Link, Theme, Renderer>>`
  15.               `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<&str>`
  16.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<Checkbox<'_, Message, Theme, Renderer>>`
  17.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<ComboBox<'_, T, Message, Theme, Renderer>>`
  18.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<Container<'_, Message, Theme, Renderer>>`
  19.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<MouseArea<'_, Message, Theme, Renderer>>`
  20.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<PaneGrid<'_, Message, Theme, Renderer>>`
  21.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<PickList<'_, T, L, V, Message, Theme, Renderer>>`
  22.            and 21 others
  23.    = note: required for `String` to implement `Into<iced_core::element::Element<'_, _, _, _>>`
  24. note: required by a bound in `button`
  25.    --> /home/laurent/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/iced_widget-0.13.4/src/helpers.rs:835:19
  26.     |
  27. 834 | pub fn button<'a, Message, Theme, Renderer>(
  28.    |        ------ required by a bound in this function
  29. 835 |     content: impl Into<Element<'a, Message, Theme, Renderer>>,
  30.     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `button`
  31.     = note: the full name for the type has been written to '/home/laurent/Documents/Programmation/Projets/Persos/Rust/skycrapers/target/debug/deps/skycrapers-1975347835c32067.long-type-12169297398742323190.txt'
  32.     = note: consider using `--verbose` to print the full type name to the console
  33. help: consider removing this method call, as the receiver has type `Cow<'_, str>` and `Cow<'_, str>: From<String>` trivially holds
  34.     |
  35.  14 - i18n!("locales", fallback = "en");
  36.  15 - use rust_i18n::t;
  37.  16 -
  38.  17 - const CELLS_SIZE: f32 = 40.0;
  39.  18 -
  40.  19 - fn main() -> iced::Result {
  41.  20 -     iced::run("Skycrapers", MyApp::update, MyApp::view)
  42.  21 - }
  43.  22 -
  44.  23 - #[derive(Debug, Clone)]
  45.  24 - enum Message {
  46.  25 -     Update(u8, u8, String),
  47.  26 -     NewGame,
  48.  27 -     Check,
  49.  28 - }
  50.  29 -
  51.  30 - struct MyApp {
  52.  31 -     size: u8,
  53.  32 -     values: Vec<Vec<String>>,
  54.  33 -     answer: Vec<Vec<u8>>,
  55.  34 -     /*
  56.  35 -        index 0 is the top line
  57.  36 -        index 1 is the bottom line
  58.  37 -        index 2 is the left line
  59.  38 -        index 3 is the right line
  60.  39 -     */
  61.  40 -     clues: Vec<Vec<u8>>,
  62.  41 -     errors: Vec<(u8, u8)>,
  63.  42 - }
  64.  43 -
  65.  44 - impl MyApp {
  66.  45 -     fn build_clue_component(&'_ self, clue: u8) -> Text<'_> {
  67.  46 -         text(format!(
  68.  47 -             "{}",
  69.  48 -             if clue != 0 {
  70.  49 -                 clue.to_string()
  71.  50 -             } else {
  72.  51 -                 String::new()
  73.  52 -             }
  74.  53 -         ))
  75.  54 -         .width(CELLS_SIZE)
  76.  55 -         .size(CELLS_SIZE)
  77.  56 -         .align_x(Horizontal::Center)
  78.  57 -     }
  79.  58 -
  80.  59 -     fn build_empty_clue_component(&'_ self) -> Text<'_> {
  81.  60 -         text("")
  82.  61 -             .width(CELLS_SIZE)
  83.  62 -             .size(CELLS_SIZE)
  84.  63 -             .align_x(Horizontal::Center)
  85.  64 -     }
  86.  65 -
  87.  66 -     fn clear_cells(&'_ mut self) {
  88. 67 -         let mut dyn_array = Vec::new();
  89. 68 -         for _row in 0..self.size {
  90. 69 -             let mut col_array = Vec::new();
  91. 70 -             for _col in 0..self.size {
  92. 71 -                 col_array.push("".to_string());
  93. 72 -             }
  94. 73 -             dyn_array.push(col_array);
  95. 74 -         }
  96. 75 -         self.values = dyn_array;
  97. 76 -     }
  98. 77 -
  99. 78 -     fn build_grid_comp(&'_ self) -> Column<'_, Message> {
  100. 79 -         let mut col_comp = Column::new();
  101. 80 -
  102. 81 -         let mut top_clues = Row::new();
  103. 82 -         top_clues = top_clues.push(self.build_empty_clue_component());
  104. 83 -         for col_index in 0..self.size {
  105. 84 -             let clue_comp = self.build_clue_component(self.clues[0][col_index as usize]);
  106. 85 -             top_clues = top_clues.push(clue_comp);
  107. 86 -         }
  108. 87 -         col_comp = col_comp.push(top_clues);
  109. 88 -
  110. 89 -         for row_index in 0..self.size {
  111. 90 -             let mut row_comp = Row::new();
  112. 91 -
  113. 92 -             let left_clue_comp = self.build_clue_component(self.clues[2][row_index as usize]);
  114. 93 -             let right_clue_comp = self.build_clue_component(self.clues[3][row_index as usize]);
  115. 94 -
  116. 95 -             row_comp = row_comp.push(left_clue_comp);
  117. 96 -
  118. 97 -             for col_index in 0..self.size {
  119. 98 -                 let is_error = self.errors.contains(&(row_index, col_index));
  120. 99 -                 let cell = text_input(
  121. 100 -                     "",
  122. 101 -                     self.values[row_index as usize][col_index as usize].as_str(),
  123. 102 -                 )
  124. 103 -                 .width(CELLS_SIZE)
  125. 104 -                 .size(CELLS_SIZE * 0.8)
  126. 105 -                 .align_x(Horizontal::Center)
  127. 106 -                 .style(move |_, _| text_input::Style {
  128. 107 -                     background: iced::Background::Color(Color::TRANSPARENT),
  129. 108 -
  130. 109 -                     border: Border {
  131. 110 -                         color: Color::BLACK,
  132. 111 -                         width: 1.0,
  133. 112 -                         radius: Radius::new(0),
  134. 113 -                     },
  135. 114 -                     icon: Color::TRANSPARENT,
  136. 115 -                     placeholder: Color::TRANSPARENT,
  137. 116 -                     selection: Color::TRANSPARENT,
  138. 117 -                     value: if is_error {
  139. 118 -                         Color::from_rgb(1.0, 0.0, 0.0)
  140. 119 -                     } else {
  141. 120 -                         Color::BLACK
  142. 121 -                     },
  143. 122 -                 })
  144. 123 -                 .on_input(move |value| Message::Update(row_index, col_index, value));
  145. 124 -                 row_comp = row_comp.push(cell);
  146. 125 -             }
  147. 126 -
  148. 127 -             row_comp = row_comp.push(right_clue_comp);
  149. 128 -
  150. 129 -             col_comp = col_comp.push(row_comp);
  151. 130 -         }
  152. 131 -
  153. 132 -         let mut bottom_clues = Row::new();
  154. 133 -         bottom_clues = bottom_clues.push(self.build_empty_clue_component());
  155. 134 -         for col_index in 0..self.size {
  156. 135 -             let clue_comp = self.build_clue_component(self.clues[1][col_index as usize]);
  157. 136 -             bottom_clues = bottom_clues.push(clue_comp);
  158. 137 -         }
  159. 138 -         col_comp = col_comp.push(bottom_clues);
  160. 139 -
  161. 140 -         col_comp
  162. 141 -     }
  163. 142 -
  164. 143 -     fn build_toolbar_comp(&self) -> Row<'_, Message> {
  165. 144 -         let new_game_button =
  166. 145 -             button(t!("ui.toolbar.new_game").to_string()).on_press(Message::NewGame);
  167.  14 + i18n!("locales", fallback = "en")).on_press(Message::NewGame);
  168.     |
  169.  
  170. error[E0277]: the trait bound `Element<'_, _, _, _>: From<String>` is not satisfied
  171.   --> src/main.rs:146:35
  172.    |
  173. 146 | ...k_button = button(t!("ui.toolbar.check").to_string()).on_press(Messa...
  174.    |               ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
  175.    |               |
  176.    |               required by a bound introduced by this call
  177.    |
  178.    = help: the trait `From<String>` is not implemented for `iced_core::element::Element<'_, _, _, _>`
  179.     = help: the following other types implement trait `From<T>`:
  180.               `iced_core::element::Element<'_, Link, Theme, Renderer>` implements `From<Rich<'_, Link, Theme, Renderer>>`
  181.               `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<&str>`
  182.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<Checkbox<'_, Message, Theme, Renderer>>`
  183.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<ComboBox<'_, T, Message, Theme, Renderer>>`
  184.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<Container<'_, Message, Theme, Renderer>>`
  185.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<MouseArea<'_, Message, Theme, Renderer>>`
  186.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<PaneGrid<'_, Message, Theme, Renderer>>`
  187.              `iced_core::element::Element<'_, Message, Theme, Renderer>` implements `From<PickList<'_, T, L, V, Message, Theme, Renderer>>`
  188.            and 21 others
  189.    = note: required for `String` to implement `Into<iced_core::element::Element<'_, _, _, _>>`
  190. note: required by a bound in `button`
  191.    --> /home/laurent/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/iced_widget-0.13.4/src/helpers.rs:835:19
  192.     |
  193. 834 | pub fn button<'a, Message, Theme, Renderer>(
  194.    |        ------ required by a bound in this function
  195. 835 |     content: impl Into<Element<'a, Message, Theme, Renderer>>,
  196.     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `button`
  197.     = note: the full name for the type has been written to '/home/laurent/Documents/Programmation/Projets/Persos/Rust/skycrapers/target/debug/deps/skycrapers-1975347835c32067.long-type-9008159889769157918.txt'
  198.     = note: consider using `--verbose` to print the full type name to the console
  199. help: consider removing this method call, as the receiver has type `Cow<'_, str>` and `Cow<'_, str>: From<String>` trivially holds
  200.     |
  201.  14 - i18n!("locales", fallback = "en");
  202.  15 - use rust_i18n::t;
  203.  16 -
  204.  17 - const CELLS_SIZE: f32 = 40.0;
  205.  18 -
  206.  19 - fn main() -> iced::Result {
  207.  20 -     iced::run("Skycrapers", MyApp::update, MyApp::view)
  208.  21 - }
  209.  22 -
  210.  23 - #[derive(Debug, Clone)]
  211.  24 - enum Message {
  212.  25 -     Update(u8, u8, String),
  213.  26 -     NewGame,
  214.  27 -     Check,
  215.  28 - }
  216.  29 -
  217.  30 - struct MyApp {
  218.  31 -     size: u8,
  219.  32 -     values: Vec<Vec<String>>,
  220.  33 -     answer: Vec<Vec<u8>>,
  221.  34 -     /*
  222.  35 -        index 0 is the top line
  223.  36 -        index 1 is the bottom line
  224.  37 -        index 2 is the left line
  225.  38 -        index 3 is the right line
  226.  39 -     */
  227.  40 -     clues: Vec<Vec<u8>>,
  228.  41 -     errors: Vec<(u8, u8)>,
  229.  42 - }
  230.  43 -
  231.  44 - impl MyApp {
  232.  45 -     fn build_clue_component(&'_ self, clue: u8) -> Text<'_> {
  233.  46 -         text(format!(
  234.  47 -             "{}",
  235.  48 -             if clue != 0 {
  236.  49 -                 clue.to_string()
  237.  50 -             } else {
  238.  51 -                 String::new()
  239.  52 -             }
  240.  53 -         ))
  241.  54 -         .width(CELLS_SIZE)
  242.  55 -         .size(CELLS_SIZE)
  243.  56 -         .align_x(Horizontal::Center)
  244.  57 -     }
  245.  58 -
  246.  59 -     fn build_empty_clue_component(&'_ self) -> Text<'_> {
  247.  60 -         text("")
  248.  61 -             .width(CELLS_SIZE)
  249.  62 -             .size(CELLS_SIZE)
  250.  63 -             .align_x(Horizontal::Center)
  251.  64 -     }
  252.  65 -
  253.  66 -     fn clear_cells(&'_ mut self) {
  254. 67 -         let mut dyn_array = Vec::new();
  255. 68 -         for _row in 0..self.size {
  256. 69 -             let mut col_array = Vec::new();
  257. 70 -             for _col in 0..self.size {
  258. 71 -                 col_array.push("".to_string());
  259. 72 -             }
  260. 73 -             dyn_array.push(col_array);
  261. 74 -         }
  262. 75 -         self.values = dyn_array;
  263. 76 -     }
  264. 77 -
  265. 78 -     fn build_grid_comp(&'_ self) -> Column<'_, Message> {
  266. 79 -         let mut col_comp = Column::new();
  267. 80 -
  268. 81 -         let mut top_clues = Row::new();
  269. 82 -         top_clues = top_clues.push(self.build_empty_clue_component());
  270. 83 -         for col_index in 0..self.size {
  271. 84 -             let clue_comp = self.build_clue_component(self.clues[0][col_index as usize]);
  272. 85 -             top_clues = top_clues.push(clue_comp);
  273. 86 -         }
  274. 87 -         col_comp = col_comp.push(top_clues);
  275. 88 -
  276. 89 -         for row_index in 0..self.size {
  277. 90 -             let mut row_comp = Row::new();
  278. 91 -
  279. 92 -             let left_clue_comp = self.build_clue_component(self.clues[2][row_index as usize]);
  280. 93 -             let right_clue_comp = self.build_clue_component(self.clues[3][row_index as usize]);
  281. 94 -
  282. 95 -             row_comp = row_comp.push(left_clue_comp);
  283. 96 -
  284. 97 -             for col_index in 0..self.size {
  285. 98 -                 let is_error = self.errors.contains(&(row_index, col_index));
  286. 99 -                 let cell = text_input(
  287. 100 -                     "",
  288. 101 -                     self.values[row_index as usize][col_index as usize].as_str(),
  289. 102 -                 )
  290. 103 -                 .width(CELLS_SIZE)
  291. 104 -                 .size(CELLS_SIZE * 0.8)
  292. 105 -                 .align_x(Horizontal::Center)
  293. 106 -                 .style(move |_, _| text_input::Style {
  294. 107 -                     background: iced::Background::Color(Color::TRANSPARENT),
  295. 108 -
  296. 109 -                     border: Border {
  297. 110 -                         color: Color::BLACK,
  298. 111 -                         width: 1.0,
  299. 112 -                         radius: Radius::new(0),
  300. 113 -                     },
  301. 114 -                     icon: Color::TRANSPARENT,
  302. 115 -                     placeholder: Color::TRANSPARENT,
  303. 116 -                     selection: Color::TRANSPARENT,
  304. 117 -                     value: if is_error {
  305. 118 -                         Color::from_rgb(1.0, 0.0, 0.0)
  306. 119 -                     } else {
  307. 120 -                         Color::BLACK
  308. 121 -                     },
  309. 122 -                 })
  310. 123 -                 .on_input(move |value| Message::Update(row_index, col_index, value));
  311. 124 -                 row_comp = row_comp.push(cell);
  312. 125 -             }
  313. 126 -
  314. 127 -             row_comp = row_comp.push(right_clue_comp);
  315. 128 -
  316. 129 -             col_comp = col_comp.push(row_comp);
  317. 130 -         }
  318. 131 -
  319. 132 -         let mut bottom_clues = Row::new();
  320. 133 -         bottom_clues = bottom_clues.push(self.build_empty_clue_component());
  321. 134 -         for col_index in 0..self.size {
  322. 135 -             let clue_comp = self.build_clue_component(self.clues[1][col_index as usize]);
  323. 136 -             bottom_clues = bottom_clues.push(clue_comp);
  324. 137 -         }
  325. 138 -         col_comp = col_comp.push(bottom_clues);
  326. 139 -
  327. 140 -         col_comp
  328. 141 -     }
  329. 142 -
  330. 143 -     fn build_toolbar_comp(&self) -> Row<'_, Message> {
  331. 144 -         let new_game_button =
  332. 145 -             button(t!("ui.toolbar.new_game").to_string()).on_press(Message::NewGame);
  333. 146 -         let check_button = button(t!("ui.toolbar.check").to_string()).on_press(Message::Check);
  334.  14 + i18n!("locales", fallback = "en")).on_press(Message::Check);
  335.     |
  336.  
  337.  
Advertisement
Add Comment
Please, Sign In to add comment