pub struct GlobalStateCreator { /* private fields */ }
Expand description

A creator for global state. This stores user-provided functions that will be invoked to generate global state on the client and the server.

The primary purpose of this is to allow the generation of top-level app state on the server and the client. Notably, this can also be interacted with by plugins.

Implementations§

source§

impl GlobalStateCreator

source

pub fn new() -> Self

Creates a new instance of this struct.

source

pub fn build_state_fn<S, V>( self, val: impl GlobalStateBuildUserFnType<S, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, V: Into<GeneratorResult<S>>,

Adds a function to generate global state at build-time.

source

pub fn build_state_fn(self, _val: impl Fn() + 'static) -> Self

Adds a function to generate global state at build-time.

source

pub fn request_state_fn<S, V>( self, val: impl GlobalStateRequestUserFnType<S, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, V: Into<BlamedGeneratorResult<S>>,

Adds a function to generate global state at request-time.

source

pub fn request_state_fn(self, _val: impl Fn() + 'static) -> Self

Adds a function to generate global state at request-time.

source

pub fn amalgamate_states_fn<S, V>( self, val: impl GlobalStateAmalgamationUserFnType<S, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,

Adds a function to amalgamate build-time and request-time global state.

source

pub fn amalgamate_states_fn(self, _val: impl Fn() + 'static) -> Self

Adds a function to amalgamate build-time and request-time global state.

source

pub async fn get_build_state(&self) -> Result<TemplateState, ServerError>

Gets the global state at build-time.

source

pub async fn get_request_state( &self, req: Request ) -> Result<TemplateState, ServerError>

Gets the global state at request-time.

source

pub async fn amalgamate_states( &self, build_state: TemplateState, request_state: TemplateState ) -> Result<TemplateState, ServerError>

Amalgamates global state that was generated at build-time with that generated at request-time, according to custom user-provided logic.

source

pub fn uses_request_state(&self) -> bool

Checks if this state needs to do anything on requests for it.

source

pub fn uses_build_state(&self) -> bool

Checks if this state needs to do anything at build time.

source

pub fn can_amalgamate_states(&self) -> bool

Checks if this state has custom logic to amalgamate build and request states if both are generated.

Trait Implementations§

source§

impl Debug for GlobalStateCreator

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GlobalStateCreator

source§

fn default() -> GlobalStateCreator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.