pub struct State<T = ()> { /* private fields */ }
Expand description
A state is a record of the env, config and associated data.
Implementations§
Source§impl<T> State<T>
impl<T> State<T>
Sourcepub fn load_config(&mut self)
pub fn load_config(&mut self)
Loads the config according to the specific env.
§Note
It supports the json
or toml
format of configuration source data,
which can be specified by the environment variable ZINO_APP_CONFIG_FORMAT
.
By default, it reads the config from a local file. If ZINO_APP_CONFIG_URL
is set,
it will fetch the config from the URL instead.
Sourcepub fn get_config(&self, key: &str) -> Option<&Table>
pub fn get_config(&self, key: &str) -> Option<&Table>
Returns a reference to the config corresponding to the key
.
Sourcepub fn get_extension_config(&self, extension: &str) -> Option<&Table>
pub fn get_extension_config(&self, extension: &str) -> Option<&Table>
Returns a reference to the config corresponding to the extension
.
Sourcepub fn parse_config<C: DeserializeOwned>(
&self,
key: &str,
) -> Option<Result<C, Error>>
pub fn parse_config<C: DeserializeOwned>( &self, key: &str, ) -> Option<Result<C, Error>>
Parses the config as an instance of C
corresponding to the key
.
Sourcepub fn parse_extension_config<C: DeserializeOwned>(
&self,
extension: &str,
) -> Option<Result<C, Error>>
pub fn parse_extension_config<C: DeserializeOwned>( &self, extension: &str, ) -> Option<Result<C, Error>>
Parses the config as an instance of C
corresponding to the extension
.
Sourcepub fn listeners(&self) -> Vec<(ServerTag, SocketAddr)>
pub fn listeners(&self) -> Vec<(ServerTag, SocketAddr)>
Returns a list of listeners.
Source§impl State
impl State
Returns a reference to the shared state.
Sourcepub fn encrypt_password(config: &Table) -> Option<Cow<'_, str>>
pub fn encrypt_password(config: &Table) -> Option<Cow<'_, str>>
Encrypts the password in the config.
Sourcepub fn decrypt_password(config: &Table) -> Option<Cow<'_, str>>
pub fn decrypt_password(config: &Table) -> Option<Cow<'_, str>>
Decrypts the password in the config.
Formats the authority in the config.
An authority can contain a username, password, host, and port number,
which is formated as {username}:{password}@{host}:{port}
.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for State<T>where
T: Freeze,
impl<T> RefUnwindSafe for State<T>where
T: RefUnwindSafe,
impl<T> Send for State<T>where
T: Send,
impl<T> Sync for State<T>where
T: Sync,
impl<T> Unpin for State<T>where
T: Unpin,
impl<T> UnwindSafe for State<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more