linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.58k stars 566 forks source link

Can't compile the program in Chapter 2 of druid book #2369

Closed HuaHuaY closed 1 year ago

HuaHuaY commented 1 year ago

book link: https://linebender.org/druid/02_getting_started.html#widget-data Source code:

use druid::widget::Label;
use druid::widget::List;
use druid::widget::{Container, Flex, Split};
use druid::Color;
use druid::{AppLauncher, Widget, WindowDesc};
use im::{vector, Vector};
type TodoList = Vector<String>;

fn build_ui() -> impl Widget<TodoList> {
    Split::columns(
        Container::new(
            // Dynamic list of Widgets
            List::new(|| Label::dynamic(|data, _| format!("List item: {data}"))),
        )
        .border(Color::grey(0.6), 2.0),
        Container::new(
            Flex::column()
                .with_flex_child(Label::new("Button placeholder"), 1.0)
                .with_flex_child(Label::new("Textbox placeholder"), 1.0),
        )
        .border(Color::grey(0.6), 2.0),
    )
}

fn main() {
    let main_window = WindowDesc::new(build_ui())
        .window_size((600.0, 400.0))
        .title("My first Druid App");
    let initial_data = vector![
        "first item".into(),
        "second item".into(),
        "third item".into(),
        "foo".into(),
        "bar".into(),
    ];

    AppLauncher::with_window(main_window)
        .launch(initial_data)
        .expect("Failed to launch application");
}

cargo run will report these:

huahua@HuaHuaATX:~/my-druid-app$ cargo run
   Compiling my-druid-app v0.1.0 (/home/huahua/my-druid-app)
error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
  --> src/main.rs:11:9
   |
11 |         Container::new(
   |         ^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `Data`:
             &'static str
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0,)
           and 100 others
note: required by a bound in `Container::<T>::new`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/container.rs:40:9
   |
40 | impl<T: Data> Container<T> {
   |         ^^^^ required by this bound in `Container::<T>::new`

error[E0277]: the trait bound `Vector<std::string::String>: ListIter<_>` is not satisfied
  --> src/main.rs:13:13
   |
11 |         Container::new(
   |         -------------- required by a bound introduced by this call
12 |             // Dynamic list of Widgets
13 |             List::new(|| Label::dynamic(|data, _| format!("List item: {data}"))),
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ListIter<_>` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `ListIter<T>`:
             <(S, std::sync::Arc<Vec<T>>) as ListIter<(S, T)>>
             <(S, std::sync::Arc<VecDeque<T>>) as ListIter<(S, T)>>
             <std::sync::Arc<Vec<T>> as ListIter<T>>
             <std::sync::Arc<VecDeque<T>> as ListIter<T>>
   = note: required for `List<_>` to implement `druid::Widget<Vector<std::string::String>>`
note: required by a bound in `Container::<T>::new`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/container.rs:42:28
   |
42 |     pub fn new(child: impl Widget<T> + 'static) -> Self {
   |                            ^^^^^^^^^ required by this bound in `Container::<T>::new`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
  --> src/main.rs:15:10
   |
15 |         .border(Color::grey(0.6), 2.0),
   |          ^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `Data`:
             &'static str
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0,)
           and 100 others
note: required by a bound in `Container::<T>::border`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/container.rs:40:9
   |
40 | impl<T: Data> Container<T> {
   |         ^^^^ required by this bound in `Container::<T>::border`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
  --> src/main.rs:17:13
   |
16 |           Container::new(
   |           -------------- required by a bound introduced by this call
17 | /             Flex::column()
18 | |                 .with_flex_child(Label::new("Button placeholder"), 1.0)
19 | |                 .with_flex_child(Label::new("Textbox placeholder"), 1.0),
   | |________________________________________________________________________^ the trait `Data` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `Data`:
             &'static str
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0,)
           and 100 others
   = note: required for `Flex<Vector<std::string::String>>` to implement `druid::Widget<Vector<std::string::String>>`
note: required by a bound in `Container::<T>::new`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/container.rs:42:28
   |
42 |     pub fn new(child: impl Widget<T> + 'static) -> Self {
   |                            ^^^^^^^^^ required by this bound in `Container::<T>::new`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
  --> src/main.rs:11:9
   |
10 |       Split::columns(
   |       -------------- required by a bound introduced by this call
11 | /         Container::new(
12 | |             // Dynamic list of Widgets
13 | |             List::new(|| Label::dynamic(|data, _| format!("List item: {data}"))),
14 | |         )
15 | |         .border(Color::grey(0.6), 2.0),
   | |______________________________________^ the trait `Data` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `Data`:
             &'static str
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0,)
           and 100 others
   = note: required for `Container<Vector<std::string::String>>` to implement `druid::Widget<Vector<std::string::String>>`
note: required by a bound in `druid::widget::Split::<T>::columns`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/split.rs:79:26
   |
79 |         left_child: impl Widget<T> + 'static,
   |                          ^^^^^^^^^ required by this bound in `Split::<T>::columns`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:17:13
    |
17  |             Flex::column()
    |             ^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `Flex::<T>::column`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/flex.rs:369:9
    |
369 | impl<T: Data> Flex<T> {
    |         ^^^^ required by this bound in `Flex::<T>::column`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:18:18
    |
18  |                 .with_flex_child(Label::new("Button placeholder"), 1.0)
    |                  ^^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `Flex::<T>::with_flex_child`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/flex.rs:369:9
    |
369 | impl<T: Data> Flex<T> {
    |         ^^^^ required by this bound in `Flex::<T>::with_flex_child`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:18:34
    |
18  |                 .with_flex_child(Label::new("Button placeholder"), 1.0)
    |                                  ^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `Label::<T>::new`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/label.rs:282:9
    |
282 | impl<T: Data> Label<T> {
    |         ^^^^ required by this bound in `Label::<T>::new`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:18:34
    |
18  |                 .with_flex_child(Label::new("Button placeholder"), 1.0)
    |                  --------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |                  |
    |                  required by a bound introduced by this call
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
    = note: required for `Label<Vector<std::string::String>>` to implement `druid::Widget<Vector<std::string::String>>`
note: required by a bound in `Flex::<T>::with_flex_child`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/flex.rs:468:21
    |
468 |         child: impl Widget<T> + 'static,
    |                     ^^^^^^^^^ required by this bound in `Flex::<T>::with_flex_child`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:19:18
    |
19  |                 .with_flex_child(Label::new("Textbox placeholder"), 1.0),
    |                  ^^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `Flex::<T>::with_flex_child`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/flex.rs:369:9
    |
369 | impl<T: Data> Flex<T> {
    |         ^^^^ required by this bound in `Flex::<T>::with_flex_child`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:19:34
    |
19  |                 .with_flex_child(Label::new("Textbox placeholder"), 1.0),
    |                                  ^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `Label::<T>::new`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/label.rs:282:9
    |
282 | impl<T: Data> Label<T> {
    |         ^^^^ required by this bound in `Label::<T>::new`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:19:34
    |
19  |                 .with_flex_child(Label::new("Textbox placeholder"), 1.0),
    |                  --------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |                  |
    |                  required by a bound introduced by this call
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
    = note: required for `Label<Vector<std::string::String>>` to implement `druid::Widget<Vector<std::string::String>>`
note: required by a bound in `Flex::<T>::with_flex_child`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/flex.rs:468:21
    |
468 |         child: impl Widget<T> + 'static,
    |                     ^^^^^^^^^ required by this bound in `Flex::<T>::with_flex_child`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
  --> src/main.rs:21:10
   |
21 |         .border(Color::grey(0.6), 2.0),
   |          ^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `Data`:
             &'static str
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0,)
           and 100 others
note: required by a bound in `Container::<T>::border`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/container.rs:40:9
   |
40 | impl<T: Data> Container<T> {
   |         ^^^^ required by this bound in `Container::<T>::border`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
  --> src/main.rs:16:9
   |
10 |       Split::columns(
   |       -------------- required by a bound introduced by this call
...
16 | /         Container::new(
17 | |             Flex::column()
18 | |                 .with_flex_child(Label::new("Button placeholder"), 1.0)
19 | |                 .with_flex_child(Label::new("Textbox placeholder"), 1.0),
20 | |         )
21 | |         .border(Color::grey(0.6), 2.0),
   | |______________________________________^ the trait `Data` is not implemented for `Vector<std::string::String>`
   |
   = help: the following other types implement trait `Data`:
             &'static str
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0,)
           and 100 others
   = note: required for `Container<Vector<std::string::String>>` to implement `druid::Widget<Vector<std::string::String>>`
note: required by a bound in `druid::widget::Split::<T>::columns`
  --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/widget/split.rs:80:27
   |
80 |         right_child: impl Widget<T> + 'static,
   |                           ^^^^^^^^^ required by this bound in `Split::<T>::columns`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
 --> src/main.rs:9:18
  |
9 | fn build_ui() -> impl Widget<TodoList> {
  |                  ^^^^^^^^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
  |
  = help: the following other types implement trait `Data`:
            &'static str
            ()
            (T0, T1)
            (T0, T1, T2)
            (T0, T1, T2, T3)
            (T0, T1, T2, T3, T4)
            (T0, T1, T2, T3, T4, T5)
            (T0,)
          and 100 others
  = note: required for `druid::widget::Split<Vector<std::string::String>>` to implement `druid::Widget<Vector<std::string::String>>`

error[E0277]: the trait bound `Vector<std::string::String>: Data` is not satisfied
   --> src/main.rs:26:23
    |
26  |     let main_window = WindowDesc::new(build_ui())
    |                       ^^^^^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<std::string::String>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `WindowDesc::<T>::new`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/app.rs:474:9
    |
474 | impl<T: Data> WindowDesc<T> {
    |         ^^^^ required by this bound in `WindowDesc::<T>::new`

error[E0599]: the method `window_size` exists for struct `WindowDesc<Vector<String>>`, but its trait bounds were not satisfied
   --> src/main.rs:27:10
    |
26  |       let main_window = WindowDesc::new(build_ui())
    |  _______________________-
27  | |         .window_size((600.0, 400.0))
    | |         -^^^^^^^^^^^ method cannot be called on `WindowDesc<Vector<String>>` due to unsatisfied trait bounds
    | |_________|
    | 
    |
   ::: /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/im-15.1.0/./src/vector/mod.rs:145:1
    |
145 |   pub struct Vector<A> {
    |   -------------------- doesn't satisfy `Vector<std::string::String>: Data`
    |
    = note: the following trait bounds were not satisfied:
            `Vector<std::string::String>: Data`

error[E0277]: the trait bound `Vector<_>: Data` is not satisfied
   --> src/main.rs:37:30
    |
37  |     AppLauncher::with_window(main_window)
    |     ------------------------ ^^^^^^^^^^^ the trait `Data` is not implemented for `Vector<_>`
    |     |
    |     required by a bound introduced by this call
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `AppLauncher::<T>::with_window`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/app.rs:142:9
    |
142 | impl<T: Data> AppLauncher<T> {
    |         ^^^^ required by this bound in `AppLauncher::<T>::with_window`

error[E0277]: the trait bound `Vector<_>: Data` is not satisfied
   --> src/main.rs:38:10
    |
38  |         .launch(initial_data)
    |          ^^^^^^ the trait `Data` is not implemented for `Vector<_>`
    |
    = help: the following other types implement trait `Data`:
              &'static str
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0,)
            and 100 others
note: required by a bound in `AppLauncher::<T>::launch`
   --> /home/huahua/.cargo/registry/src/index.crates.io-6f17d22bba15001f/druid-0.8.3/src/app.rs:142:9
    |
142 | impl<T: Data> AppLauncher<T> {
    |         ^^^^ required by this bound in `AppLauncher::<T>::launch`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `my-druid-app` (bin "my-druid-app") due to 19 previous errors
HuaHuaY commented 1 year ago

My mistake. I searched for "im::" in the code of this repo and found that the "im" feature of druid needs to be added.