Skip to main content

AppState

Struct AppState 

Source
pub struct AppState<T> { /* private fields */ }
Expand description

Wraps a value so it can be used as application state with DefaultError.

AppState<T> implements State for any 'static T, so a separate State implementation is not needed. It dereferences to the wrapped value and implements Clone and Default when T does.

use ntex::web;

#[derive(Clone)]
struct Settings {
    service_name: &'static str,
}

let state = web::AppState::new(Settings { service_name: "users" });
assert_eq!(state.service_name, "users");

Implementations§

Source§

impl<T> AppState<T>

Source

pub fn new(state: T) -> Self

Creates application state that wraps state.

Source

pub fn st(&self) -> &T

Returns a reference to the wrapped value.

Trait Implementations§

Source§

impl<T: Clone> Clone for AppState<T>

Source§

fn clone(&self) -> AppState<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Default> Default for AppState<T>

Source§

fn default() -> AppState<T>

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

impl<T> Deref for AppState<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: 'static> State for AppState<T>

Source§

type Error = DefaultError

Error domain used by the application.

Auto Trait Implementations§

§

impl<T> Freeze for AppState<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AppState<T>
where T: RefUnwindSafe,

§

impl<T> Send for AppState<T>
where T: Send,

§

impl<T> Sync for AppState<T>
where T: Sync,

§

impl<T> Unpin for AppState<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for AppState<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for AppState<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Formattable for T
where T: Deref, <T as Deref>::Target: Formattable,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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.

§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.