pub trait FromView<S: 'static, D>: Sized {
type Item<'f>;
// Required method
fn from_view<'f>(cx: &'f ViewContext<'_, S>) -> Self::Item<'f>;
}Expand description
Types that can be extracted for a view, used as arguments of page, layout and error views.
S is the app state and D the data of the view: what its load returned
(() without one), or the RouteError for error pages. Item is the
extractor with the lifetime of the frame, e.g. Nav<'f> for Nav<'_>.
A custom extractor, e.g. for the signed-in user:
use egui_kit::page::ViewContext;
use egui_kit::extract::FromView;
#[derive(Clone)]
struct AppState {
user: Option<String>,
}
struct User(Option<String>);
impl<D> FromView<AppState, D> for User {
type Item<'f> = User;
fn from_view(cx: &ViewContext<'_, AppState>) -> User {
User(cx.state().user.clone())
}
}Required Associated Types§
Required Methods§
fn from_view<'f>(cx: &'f ViewContext<'_, S>) -> Self::Item<'f>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<S: 'static, D: 'static> FromView<S, D> for &mut D
The view’s data: what its load returned, or the error of an error page.
impl<S: 'static, D: 'static> FromView<S, D> for &mut D
The view’s data: what its load returned, or the error of an error page.