maciejhirsz / kobold

Easy declarative web interfaces.
https://docs.rs/kobold/
Mozilla Public License 2.0
385 stars 7 forks source link

Example of using the `get` function implementation of `Hook` #55

Closed ltfschoen closed 1 year ago

ltfschoen commented 1 year ago

Example of using the get function implementation of Hook https://docs.rs/kobold/latest/kobold/stateful/struct.Hook.html#method.get, which states "Get the value of state if state implements Copy", where I've used a state that is just a struct State that has a my_state property with a bool type so it can implement the Copy trait, since if the State has properties of types that don't automatically implement the Copy trait (i.e. Vec, String, Range, Box) then you get errors like:

error[E0204]: the trait `Copy` may not be implemented for this type
  --> examples/invoice/src/state.rs:33:32
   |
33 | #[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
   |                                ^^^^
...
39 |     pub qr_code: String,
   |     ------------------- this field does not implement `Copy`
   |
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0204]: the trait `Copy` may not be implemented for this type
  --> examples/invoice/src/state.rs:41:32
   |
41 | #[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
   |                                ^^^^
42 | pub struct Entry {
43 |     pub description: String,
   |     ----------------------- this field does not implement `Copy`
   |
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0204]: the trait `Copy` may not be implemented for this type
  --> examples/invoice/src/state.rs:47:32
   |
47 | #[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
   |                                ^^^^
...
50 |     pub columns: Vec<Text>,
   |     ---------------------- this field does not implement `Copy`
51 |     pub rows: Vec<Vec<Text>>,
   |     ------------------------ this field does not implement `Copy`
   |
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0204]: the trait `Copy` may not be implemented for this type
  --> examples/invoice/src/state.rs:54:32
   |
54 | #[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
   |                                ^^^^
55 | pub enum Text {
56 |     Insitu(Range<usize>),
   |            ------------ this field does not implement `Copy`
57 |     Owned(Box<str>),
   |           -------- this field does not implement `Copy`
   |
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0204]: the trait `Copy` may not be implemented for this type
   --> examples/invoice/src/state.rs:204:32
    |
204 | #[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
    |                                ^^^^
205 | pub struct TextSource {
206 |     pub source: String,
    |     ------------------ this field does not implement `Copy`

But if i try to use stateful::Signal public function .set https://docs.rs/kobold/latest/kobold/stateful/struct.Signal.html#method.set, which says it's used to "Replace the entire state with a new value and trigger an update.", it doesn't change the state at all as expected, i thought it would have set the my_state value to true

Screen Shot 2023-04-04 at 12 24 31 pm
maciejhirsz commented 1 year ago

Per discussion in #56 Signal::set is fixed in #64.

I don't necessarily want to change the hello_world from what it is right now, definitely don't want to add a bunch of debug logs to it either. I'll probably work on a new basic example with stateful and event handling that will be front-and-center in the README for 0.7 release.