pub trait DefaultContext: Default {
// Required methods
fn default_key() -> &'static str;
fn from_context(context: Context) -> Option<Self>;
fn cast(context: &Context) -> Option<&Self>;
fn cast_mut(context: &mut Context) -> Option<&mut Self>;
fn into_context(self) -> Context;
}
Expand description
A well-known context in the Contexts
interface.
These contexts have a default key in the contexts map and can be constructed as an empty default value.
Required Methods§
Sourcefn default_key() -> &'static str
fn default_key() -> &'static str
The default key at which this context resides in Contexts
.
Sourcefn from_context(context: Context) -> Option<Self>
fn from_context(context: Context) -> Option<Self>
Converts this context type from a generic context type.
Returns Some
if the context is of this type. Otherwise, returns None
.
Sourcefn cast(context: &Context) -> Option<&Self>
fn cast(context: &Context) -> Option<&Self>
Casts a reference to this context type from a generic context type.
Returns Some
if the context is of this type. Otherwise, returns None
.
Sourcefn cast_mut(context: &mut Context) -> Option<&mut Self>
fn cast_mut(context: &mut Context) -> Option<&mut Self>
Casts a mutable reference to this context type from a generic context type.
Returns Some
if the context is of this type. Otherwise, returns None
.
Sourcefn into_context(self) -> Context
fn into_context(self) -> Context
Boxes this context type in the generic context wrapper.
Returns Some
if the context is of this type. Otherwise, returns None
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.