Closed spencewenski closed 3 days ago
Yeah, we should change how we have consumers provide custom state to follow the recommendation from Axum: https://docs.rs/axum/0.7.5/axum/extract/struct.State.html#for-library-authors. Not only would this be in-line with the recommendation, but I believe is required in order to allow consumers to use Leptos.
Example:
#[derive(Clone)]
struct RoadsterState {
foo: String,
}
#[derive(Clone, FromRef)]
struct CustomState {
bar: String,
foo: RoadsterState,
}
fn baz<S>(s: S)
where
RoadsterState: FromRef<S>,
{
let roadster_state = RoadsterState::from_ref(&s);
}
but I believe is required in order to allow consumers to use Leptos.
This may not be 100% true -- we could potentially provide the required leptos state from the Roadster AppContext directly (and implement FromRef on AppContext). However, that would only solve this for Leptos, and not any other library that a consumer may want to use that had similar requirements.
This will likely be a breaking change.
where RoadsterState: FromRef<S>
I didn’t even know it was possible to write type bounds like this. This is pretty cool. We’re probably going to need to change a bunch of stuff to use this approach. I’m also not sure how this will impact our http service builder, and a bunch of other stuff… this is going to be a big change…
Completed in https://github.com/roadster-rs/roadster/pull/250
This may be required in order to integrate with Leptos