diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 43612bb120f..15e8d96e540 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -198,7 +198,7 @@ jobs: strategy: matrix: toolchain: - - 1.45.0 # MSRV + - 1.51.0 # min version with const generics - stable - nightly diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c568dce42a4..214248d24ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,9 +68,10 @@ Alternatively, you can set the `ECHO_SERVER_URL` environment variable to the URL When adding or updating tests, please make sure to update the appropriate `stderr` file, which you can find [here](https://github.com/yewstack/yew/tree/master/packages/yew-macro/tests/macro) for the `html!` macro. These files ensure that macro compilation errors are correct and easy to understand. -These errors can change with each release of the compiler so they should be generated with the MSRV (currently 1.45). +These errors can change with each release of the compiler so they should be generated with the Rust version 1.51 +(because some tests make use of const generics which were stabilized in that version). -To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo +1.45.2 test` in the `yew-macro` directory. +To update or generate a new `stderr` file you can run `cargo make test-overwrite` in the `yew-macro` directory. ## Linting diff --git a/docs/concepts/function-components/attribute.md b/docs/concepts/function-components/attribute.md index 4dd99078eae..b02ac6febb6 100644 --- a/docs/concepts/function-components/attribute.md +++ b/docs/concepts/function-components/attribute.md @@ -30,7 +30,7 @@ pub fn rendered_at(props: &RenderedAtProps) -> Html { html! {

{ "Rendered at: " } - { &props.time } + { props.time.clone() }

} } @@ -46,7 +46,7 @@ fn app() -> Html { let counter = Rc::clone(&counter); Callback::from(move |_| set_counter(*counter + 1)) }; - + html! {
diff --git a/docs/concepts/html/components.md b/docs/concepts/html/components.md index c0e6fae8bec..d134d973e00 100644 --- a/docs/concepts/html/components.md +++ b/docs/concepts/html/components.md @@ -67,7 +67,7 @@ impl Component for Container { fn view(&self) -> Html { html! { -
+
{ self.0.children.clone() }
} @@ -112,45 +112,6 @@ impl Component for List { } ``` -## Transformers - -Whenever you set a prop its value goes through a transformation step first. -If the value already has the correct type, this step doesn't do anything. -However, transformers can be useful to reduce code repetition. - -The following is a list of transformers you should know about: - -- `&T` -> `T` - - Clones the reference to get an owned value. - -- `&str` -> `String` - - Allows you to use string literals without adding `.to_owned()` at the end. - -- `T` -> `Option` - - Wraps the value in `Some`. - -```rust -struct Props { - unique_id: Option, - text: String, -} - -struct Model; -impl Component for Model { - type Properties = Props; - - // ... -} - -// transformers allow you to write this: -html! { }; -// instead of: -html! { }; -``` - ## Relevant examples - [Boids](https://github.com/yewstack/yew/tree/master/examples/boids) - [Router](https://github.com/yewstack/yew/tree/master/examples/router) diff --git a/docs/concepts/html/elements.md b/docs/concepts/html/elements.md index dba75480f91..92d3e451045 100644 --- a/docs/concepts/html/elements.md +++ b/docs/concepts/html/elements.md @@ -15,26 +15,36 @@ let level = 5; let text = "Hello World!".to_owned() html! { - <@{format!("h{}", level)} class="title">{ content } + <@{format!("h{}", level)} class="title">{ text } } ``` ## Optional attributes for HTML elements -Most HTML attributes can be marked as optional by placing a `?` in front of -the `=` sign. This makes them accept the same type of value as otherwise, but -wrapped in an `Option`: +Most HTML attributes can use optional values (`Some(x)` or `None`). This allows us +to omit the attribute if the attribute is marked as optional. ```rust let maybe_id = Some("foobar"); html! { -
+
} ``` If the attribute is set to `None`, the attribute won't be set in the DOM. +Please note that it is also valid to give only the value as properties behave +like `Into>`: + +```rust +let id = "foobar"; + +html! { +
+} +``` + ## Listeners Listener attributes need to be passed a `Callback` which is a wrapper around a closure. How you create your callback depends on how you wish your app to react to a listener event: diff --git a/examples/boids/src/slider.rs b/examples/boids/src/slider.rs index a86c77f82e8..f98be3d01ee 100644 --- a/examples/boids/src/slider.rs +++ b/examples/boids/src/slider.rs @@ -80,13 +80,13 @@ impl Component for Slider { html! {
- + { display_value }
diff --git a/examples/crm/src/add_client.rs b/examples/crm/src/add_client.rs index ed2683092cf..f5eba187286 100644 --- a/examples/crm/src/add_client.rs +++ b/examples/crm/src/add_client.rs @@ -78,19 +78,19 @@ impl Component for AddClientForm {