Struct cursive_core::builder::Context
source · pub struct Context { /* private fields */ }Expand description
Everything needed to prepare a view from a config.
- Current blueprints
- Any stored variables/callbacks
Cheap to clone (uses Arc internally).
Implementations§
source§impl Context
impl Context
sourcepub fn resolve_as_var<T: 'static + Resolvable>(
&self,
config: &Config,
) -> Result<T, Error>
pub fn resolve_as_var<T: 'static + Resolvable>( &self, config: &Config, ) -> Result<T, Error>
Resolve a value.
Needs to be a reference to a variable.
sourcepub fn resolve_as_config<T: Resolvable + 'static>(
&self,
config: &Config,
) -> Result<T, Error>
pub fn resolve_as_config<T: Resolvable + 'static>( &self, config: &Config, ) -> Result<T, Error>
Resolve a value straight from the config.
This will not attempt to load the value as a variable if the config is a string.
Note however that while loading as a config, it may still resolve nested values as variables.
sourcepub fn resolve<T: Resolvable + 'static>(
&self,
config: &Config,
) -> Result<T, Error>
pub fn resolve<T: Resolvable + 'static>( &self, config: &Config, ) -> Result<T, Error>
Resolve a value
sourcepub fn resolve_or<T: Resolvable + 'static>(
&self,
config: &Config,
if_missing: T,
) -> Result<T, Error>
pub fn resolve_or<T: Resolvable + 'static>( &self, config: &Config, if_missing: T, ) -> Result<T, Error>
Resolve a value, using the given default if the key is missing.
sourcepub fn store_once<T>(&mut self, name: impl Into<String>, value: T)where
T: Send + 'static,
pub fn store_once<T>(&mut self, name: impl Into<String>, value: T)where
T: Send + 'static,
Store a new variable that can only be resolved once.
sourcepub fn store_with<T: 'static>(
&mut self,
name: impl Into<String>,
maker: impl 'static + Fn(&Config, &Context) -> Result<T, Error> + Send + Sync,
)
pub fn store_with<T: 'static>( &mut self, name: impl Into<String>, maker: impl 'static + Fn(&Config, &Context) -> Result<T, Error> + Send + Sync, )
Store a new variable maker.
sourcepub fn store<S, T>(&mut self, name: S, value: T)
pub fn store<S, T>(&mut self, name: S, value: T)
Store a new variable for resolution.
Can be a callback, a usize, …
sourcepub fn store_view<S, T>(&mut self, name: S, view: T)
pub fn store_view<S, T>(&mut self, name: S, view: T)
Store a view for resolution.
The view can be resolved as a BoxedView.
Note that this will only resolve this view once.
If the view should be resolved more than that, consider calling store_with and
re-constructing a BoxedView (maybe by cloning your view) every time.
sourcepub fn store_config(
&mut self,
name: impl Into<String>,
config: impl Into<Config>,
)
pub fn store_config( &mut self, name: impl Into<String>, config: impl Into<Config>, )
Store a new config.
sourcepub fn store_proxy(
&mut self,
name: impl Into<String>,
new_name: impl Into<String>,
)
pub fn store_proxy( &mut self, name: impl Into<String>, new_name: impl Into<String>, )
Store a new variable proxy.
sourcepub fn register_blueprint<F>(&mut self, name: impl Into<String>, blueprint: F)
pub fn register_blueprint<F>(&mut self, name: impl Into<String>, blueprint: F)
Register a new blueprint for this context only.
sourcepub fn register_wrapper_blueprint<F>(
&mut self,
name: impl Into<String>,
blueprint: F,
)
pub fn register_wrapper_blueprint<F>( &mut self, name: impl Into<String>, blueprint: F, )
Register a new wrapper blueprint for this context only.
sourcepub fn load<T: Resolvable + Any>(
&self,
name: &str,
config: &Config,
) -> Result<T, Error>
pub fn load<T: Resolvable + Any>( &self, name: &str, config: &Config, ) -> Result<T, Error>
Loads a variable of the given type.
If a variable with this name is found but is a Config, tries to deserialize it.
Note: config can be &Config::Null for loading simple variables.
sourcepub fn build_wrapper(&self, config: &Config) -> Result<Wrapper, Error>
pub fn build_wrapper(&self, config: &Config) -> Result<Wrapper, Error>
Build a wrapper with the given config
sourcepub fn validate(&self, config: &Config) -> Result<(), ConfigError>
pub fn validate(&self, config: &Config) -> Result<(), ConfigError>
Validate a config.
Returns an error if any variable is missing or used more than once.
sourcepub fn build(&self, config: &Config) -> Result<BoxedView, Error>
pub fn build(&self, config: &Config) -> Result<BoxedView, Error>
Build a new view from the given config.
sourcepub fn sub_context<F>(&self, f: F) -> Context
pub fn sub_context<F>(&self, f: F) -> Context
Prepare a new context with some variable overrides.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)