Skip to main content

FromView

Trait FromView 

Source
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§

Source

type Item<'f>

Required Methods§

Source

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 &D

Read-only access to the view’s data.

Source§

type Item<'f> = &'f D

Source§

fn from_view<'f>(cx: &'f ViewContext<'_, S>) -> &'f D

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.

Source§

type Item<'f> = &'f mut D

Source§

fn from_view<'f>(cx: &'f ViewContext<'_, S>) -> &'f mut D

Implementors§

Source§

impl<S: 'static, D, T: Any> FromView<S, D> for HistoryState<&T>

Source§

impl<S: 'static, D, T: Default + 'static> FromView<S, D> for PageState<'_, T>

Source§

type Item<'f> = PageState<'f, T>

Source§

impl<S: 'static, D, T: Default + 'static> FromView<S, D> for Snapshot<'_, T>

Source§

type Item<'f> = Snapshot<'f, T>

Source§

impl<S: 'static, D, T: FromRef<S> + 'static> FromView<S, D> for State<&T>

Source§

impl<S: 'static, D, T> FromView<S, D> for PersistentState<'_, T>
where T: Serialize + DeserializeOwned + Clone + Default + Send + Sync + 'static,

Source§

type Item<'f> = PersistentState<'f, T>

Source§

impl<S: 'static, D> FromView<S, D> for Nav<'_>

Source§

type Item<'f> = Nav<'f>

Source§

impl<S: 'static, D> FromView<S, D> for Navigation

How the page was reached.

Source§

impl<S: 'static, D> FromView<S, D> for Remote<'_, S>

Source§

type Item<'f> = Remote<'f, S>

Source§

impl<S: 'static, D> FromView<S, D> for Request

The url the page was loaded with and the parameters of its route. Unaffected by shallow routing, see Nav::url.

Source§

impl<S: 'static, D> FromView<S, D> for Scroll<'_>

Source§

type Item<'f> = Scroll<'f>