lpotthast/leptonic

What does this error message mean, am I missing something?

lhjok opened this issue · 9 comments

lhjok commented
error[E0432]: unresolved imports `leptos_use::use_element_size`, `leptos_use::UseElementSizeReturn`
 --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/progress_bar.rs:2:18
  |
2 | use leptos_use::{use_element_size, UseElementSizeReturn};
  |                  ^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^ no `UseElementSizeReturn` in the root
  |                  |
  |                  no `use_element_size` in the root
  |                  help: a similar name exists in the module: `use_element_hover`

error[E0432]: unresolved imports `leptos_use::use_element_size`, `leptos_use::UseElementSizeReturn`
 --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/skeleton.rs:2:18
  |
2 | use leptos_use::{use_element_size, UseElementSizeReturn};
  |                  ^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^ no `UseElementSizeReturn` in the root
  |                  |
  |                  no `use_element_size` in the root
  |                  help: a similar name exists in the module: `use_element_hover`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `leptonic` (lib) due to 2 previous errors
2023-08-18T19:05:55.820210Z ERROR ❌ error

leptonic depends on leptos_use. Some of it's functions require an opt-in.

To resolve your problem, create a directory named .cargo and place a config.toml file with the following content inside it:

[build]
# The 'web_sys_unstable_apis' flag is required, because we use https://leptos-use.rs/elements/use_element_size.html which states this requirement. This might change in the future.
rustflags = ["--cfg=web_sys_unstable_apis"]

Thanks for pointing this out. I'll add this to the documentation.

lhjok commented
error[E0277]: expected a `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
  --> src/views/login.rs:56:45
   |
56 | ...                   <Input get=name set=set_name label="This is my label"/>
   |                                       ^^^ expected an `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
   |
   = help: the trait `FnOnce<(std::string::String,)>` is not implemented for `WriteSignal<std::string::String>`
note: required by a bound in `InputPropsBuilder::<S, (__ty, __label, __get, (), __prepend, __id, __class, __disabled, __should_be_focused, __on_focus_change, __autofocus, __style)>::set`
  --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/input.rs:69:8
   |
58 |     set: S,
   |     --- required by a bound in this associated function
...
69 |     S: Fn(String) + Clone + 'static,
   |        ^^^^^^^^^^ required by this bound in `InputPropsBuilder::<S, (__ty, __label, __get, (), __prepend, __id, __class, __disabled, __should_be_focused, __on_focus_change, __autofocus, __style)>::set`

error[E0277]: expected a `std::ops::Fn<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
   --> src/views/login.rs:45:5
    |
45  | /     view! { cx,
46  | |         <section class="h-screen">
47  | |             <div class="container h-full px-6 py-24 mx-auto max-w-7xl">
48  | |                 <div
...   |
56  | |                             <Input get=name set=set_name label="This is my label"/>
    | |                                    --- required by a bound introduced by this call
...   |
119 | |         </section>
120 | |     }
    | |_____^ expected an `Fn<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
    |
    = help: the trait `std::ops::Fn<(std::string::String,)>` is not implemented for `WriteSignal<std::string::String>`
note: required by a bound in `InputPropsBuilder::<S, (__ty, __label, (), __set, __prepend, __id, __class, __disabled, __should_be_focused, __on_focus_change, __autofocus, __style)>::get`
   --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/input.rs:69:8
    |
57  |     #[prop(into)] get: MaybeSignal<String>,
    |                   --- required by a bound in this associated function
...
69  |     S: Fn(String) + Clone + 'static,
    |        ^^^^^^^^^^ required by this bound in `InputPropsBuilder::<S, (__ty, __label, (), __set, __prepend, __id, __class, __disabled, __should_be_focused, __on_focus_change, __autofocus, __style)>::get`

error[E0277]: expected a `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
  --> src/views/login.rs:56:30
   |
56 | ...                   <Input get=name set=set_name label="This is my label"/>
   |                        ^^^^^ expected an `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
   |
   = help: the trait `FnOnce<(std::string::String,)>` is not implemented for `WriteSignal<std::string::String>`
note: required by a bound in `leptonic::input::Input`
  --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/input.rs:69:8
   |
53 | pub fn Input<S>(
   |        ----- required by a bound in this function
...
69 |     S: Fn(String) + Clone + 'static,
   |        ^^^^^^^^^^ required by this bound in `Input`

error[E0277]: expected a `std::ops::Fn<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
   --> src/views/login.rs:45:5
    |
45  | /     view! { cx,
46  | |         <section class="h-screen">
47  | |             <div class="container h-full px-6 py-24 mx-auto max-w-7xl">
48  | |                 <div
...   |
119 | |         </section>
120 | |     }
    | |_____^ expected an `Fn<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
    |
    = help: the trait `std::ops::Fn<(std::string::String,)>` is not implemented for `WriteSignal<std::string::String>`
    = note: required for `InputProps<WriteSignal<std::string::String>>` to implement `leptos::Props`
    = note: required for `fn(leptos::Scope, InputProps<WriteSignal<std::string::String>>) -> impl leptos::IntoView {leptonic::input::Input::<WriteSignal<std::string::String>>}` to implement `leptos::Component<InputProps<WriteSignal<std::string::String>>>`
note: required by a bound in `component_props_builder`
   --> /var/home/lhjok/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos-0.4.8/src/lib.rs:283:15
    |
282 | pub fn component_props_builder<P: PropsOrNoPropsBuilder>(
    |        ----------------------- required by a bound in this function
283 |     _f: &impl Component<P>,
    |               ^^^^^^^^^^^^ required by this bound in `component_props_builder`
    = note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the method `label` exists for struct `InputPropsBuilder<WriteSignal<String>, ((), (), (MaybeSignal<String>,), (WriteSignal<String>,), (), (), (), (), (), (), (), ())>`, but its trait bounds were not satisfied
   --> src/views/login.rs:56:58
    |
45  | /     view! { cx,
46  | |         <section class="h-screen">
47  | |             <div class="container h-full px-6 py-24 mx-auto max-w-7xl">
48  | |                 <div
...   |
55  | |                         <form>
56  | |                             <Input get=name set=set_name label="This is my label"/>
    | |                                                         -^^^^^ method cannot be called due to unsatisfied trait bounds
    | |_________________________________________________________|
    | 
    |
   ::: /var/home/lhjok/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_reactive-0.4.8/src/signal.rs:867:1
    |
867 |   pub struct WriteSignal<T>
    |   -------------------------
    |   |
    |   doesn't satisfy `<_ as FnOnce<(String,)>>::Output = ()`
    |   doesn't satisfy `_: Fn<(String,)>`
    |   doesn't satisfy `_: FnMut<(String,)>`
    |   doesn't satisfy `_: FnOnce<(String,)>`
    |
    = note: the full type name has been written to '/var/home/lhjok/文档/Leptos-rs/target/wasm32-unknown-unknown/debug/deps/Leptos_rs-c153743eaa2c05cb.long-type-7801878424866246742.txt'
    = note: the following trait bounds were not satisfied:
            `<WriteSignal<std::string::String> as FnOnce<(std::string::String,)>>::Output = ()`
            `WriteSignal<std::string::String>: std::ops::Fn<(std::string::String,)>`
            `WriteSignal<std::string::String>: FnMut<(std::string::String,)>`
            which is required by `WriteSignal<std::string::String>: std::ops::Fn<(std::string::String,)>`
            `WriteSignal<std::string::String>: FnOnce<(std::string::String,)>`
            which is required by `WriteSignal<std::string::String>: std::ops::Fn<(std::string::String,)>`

error[E0277]: expected a `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
  --> src/views/login.rs:57:68
   |
57 | ...                   <Input ty=InputType::Password get=pass set=set_pass/>
   |                                                              ^^^ expected an `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
   |
   = help: the trait `FnOnce<(std::string::String,)>` is not implemented for `WriteSignal<std::string::String>`
note: required by a bound in `InputPropsBuilder::<S, (__ty, __label, __get, (), __prepend, __id, __class, __disabled, __should_be_focused, __on_focus_change, __autofocus, __style)>::set`
  --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/input.rs:69:8
   |
58 |     set: S,
   |     --- required by a bound in this associated function
...
69 |     S: Fn(String) + Clone + 'static,
   |        ^^^^^^^^^^ required by this bound in `InputPropsBuilder::<S, (__ty, __label, __get, (), __prepend, __id, __class, __disabled, __should_be_focused, __on_focus_change, __autofocus, __style)>::set`

error[E0277]: expected a `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
  --> src/views/login.rs:57:30
   |
57 | ...                   <Input ty=InputType::Password get=pass set=set_pass/>
   |                        ^^^^^ expected an `FnOnce<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`
   |
   = help: the trait `FnOnce<(std::string::String,)>` is not implemented for `WriteSignal<std::string::String>`
note: required by a bound in `leptonic::input::Input`
  --> /var/home/lhjok/.cargo/git/checkouts/leptonic-09c2066a1d051b46/c10671e/leptonic/src/input.rs:69:8
   |
53 | pub fn Input<S>(
   |        ----- required by a bound in this function
...
69 |     S: Fn(String) + Clone + 'static,
   |        ^^^^^^^^^^ required by this bound in `Input`

error[E0599]: the method `build` exists for struct `InputPropsBuilder<WriteSignal<String>, ((InputType,), (), (MaybeSignal<String>,), (...,), ..., ..., ..., ..., ..., ..., ..., ...)>`, but its trait bounds were not satisfied
   --> src/views/login.rs:45:5
    |
45  |       view! { cx,
    |  _____^
46  | |         <section class="h-screen">
47  | |             <div class="container h-full px-6 py-24 mx-auto max-w-7xl">
48  | |                 <div
...   |
119 | |         </section>
120 | |     }
    | |_____^ method cannot be called due to unsatisfied trait bounds
    |
   ::: /var/home/lhjok/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_reactive-0.4.8/src/signal.rs:867:1
    |
867 |   pub struct WriteSignal<T>
    |   -------------------------
    |   |
    |   doesn't satisfy `<_ as FnOnce<(String,)>>::Output = ()`
    |   doesn't satisfy `_: Fn<(String,)>`
    |   doesn't satisfy `_: FnMut<(String,)>`
    |   doesn't satisfy `_: FnOnce<(String,)>`
    |
    = note: the full type name has been written to '/var/home/lhjok/文档/Leptos-rs/target/wasm32-unknown-unknown/debug/deps/Leptos_rs-c153743eaa2c05cb.long-type-8968674277120014160.txt'
    = note: the following trait bounds were not satisfied:
            `<WriteSignal<std::string::String> as FnOnce<(std::string::String,)>>::Output = ()`
            `WriteSignal<std::string::String>: std::ops::Fn<(std::string::String,)>`
            `WriteSignal<std::string::String>: FnMut<(std::string::String,)>`
            which is required by `WriteSignal<std::string::String>: std::ops::Fn<(std::string::String,)>`
            `WriteSignal<std::string::String>: FnOnce<(std::string::String,)>`
            which is required by `WriteSignal<std::string::String>: std::ops::Fn<(std::string::String,)>`
    = note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
The following warnings were emitted during compilation:

warning: theme written
warning: js dir created
warning: tiptap-bundle.min.js written
warning: tiptap.js written

error: could not compile `Leptos-rs` (bin "Leptos-rs") due to 8 previous errors
2023-08-19T05:50:20.474302Z ERROR ❌ error
error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: error during cargo build execution
    2: cargo call returned a bad status

I ran into this problem again.

lhjok commented
<Input get=text set=set_text label="This is my label"/>

It seems that set_text cannot be called directly, and it will report the same error as above. Is there something I am missing?

This is the relevant part of the output you posted:

expected a `std::ops::Fn<(std::string::String,)>` closure, found `WriteSignal<std::string::String>`

Use

<Input get=text set=move |v| set_text.set(v) label="This is my label"/>

instead.

The set prop is not defined to receive a WriteSignal. It expects a Fn closure receiving the new value as its only argument. The reason for that is that sometimes you do not want to stick a new value directly back into a signal, but rather want to process it before doing so. Or you may want to do something entirely different than storing it using a WriteSignal.

I might add an abstraction that allows users to pass either a WriteSignal or a closure, so that this (your) case (which also comes up often) is made more easy.

lhjok commented

Your case shows that it is directly callable, so I assumed you had already taken care of it, great ui library!!!!

Ohh. Sorry, my bad. I'm correcting the documentation. I think I already stated to use set=set_text because I wanted to change the API to support that and never came to do that...
Experimented a bit. The set prop will no longer be generic in the future. I now defined it as

#[prop(into, optional)] set: Option<Out<String>>,

withOut being a new type provided by leptonic, defined:

pub enum Out<O: 'static> {
    Callback(Callback<O, ()>),
    WriteSignal(WriteSignal<O>),
}

impl<O: 'static> Out<O> {
    pub fn set(&self, new_value: O) {
        match self {
            Out::Callback(callback) => callback.call(new_value),
            Out::WriteSignal(write_signal) => write_signal.set(new_value),
        }
    }
}

impl<O: 'static> From<Callback<O>> for Out<O> {
    fn from(callback: Callback<O>) -> Self {
        Out::Callback(callback)
    }
}

impl<O: 'static> From<WriteSignal<O>> for Out<O> {
    fn from(write_signal: WriteSignal<O>) -> Self {
        Out::WriteSignal(write_signal)
    }
}

So one can either use

<Input get=text set=set_text>

or

<Input get=text set=create_callback(cx, move |v| set_text.set(v))>

with the later one becoming simpler when leptos 0.5 is released. Either

<Input get=text set=create_callback(move |v| set_text.set(v))>

or, if possible, just

<Input get=text set=move |v| set_text.set(v)>
lhjok commented

The developer of leptos, gbj, recommended for me to use leptonic, which exceeded my expectations, I just didn't expect the project to grow so fast, I see that the project has just been created. I hope to see continued development.

That was very kind of him. I'm also using this library for an internal software. Development will continue. Feel free to open new issues for suggestions, missing components or quality-of-life improvements.