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

source

pub fn new() -> Self

Prepare a new context using registered blueprints.

source

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.

source

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.

source

pub fn resolve<T: Resolvable + 'static>( &self, config: &Config, ) -> Result<T, Error>

Resolve a value

source

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.

source

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.

source

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.

source

pub fn store<S, T>(&mut self, name: S, value: T)
where S: Into<String>, T: Clone + Send + Sync + 'static,

Store a new variable for resolution.

Can be a callback, a usize, …

source

pub fn store_view<S, T>(&mut self, name: S, view: T)
where S: Into<String>, T: IntoBoxedView,

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.

source

pub fn store_config( &mut self, name: impl Into<String>, config: impl Into<Config>, )

Store a new config.

source

pub fn store_proxy( &mut self, name: impl Into<String>, new_name: impl Into<String>, )

Store a new variable proxy.

source

pub fn register_blueprint<F>(&mut self, name: impl Into<String>, blueprint: F)
where F: Fn(&Config, &Context) -> Result<BoxedView, Error> + 'static + Send + Sync,

Register a new blueprint for this context only.

source

pub fn register_wrapper_blueprint<F>( &mut self, name: impl Into<String>, blueprint: F, )
where F: Fn(&Config, &Context) -> Result<Wrapper, Error> + 'static + Send + Sync,

Register a new wrapper blueprint for this context only.

source

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.

source

pub fn build_wrapper(&self, config: &Config) -> Result<Wrapper, Error>

Build a wrapper with the given config

source

pub fn validate(&self, config: &Config) -> Result<(), ConfigError>

Validate a config.

Returns an error if any variable is missing or used more than once.

source

pub fn build(&self, config: &Config) -> Result<BoxedView, Error>

Build a new view from the given config.

source

pub fn sub_context<F>(&self, f: F) -> Context
where F: FnOnce(&mut Context),

Prepare a new context with some variable overrides.

source

pub fn build_template( &self, config: &Config, template: &Config, ) -> Result<BoxedView, Error>

Builds a view from a template config.

template should be a config describing a view, potentially using variables. Any value in config will be stored as a variable when rendering the template.

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for Context

source§

fn default() -> Self

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

Auto Trait Implementations§

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 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.

source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> With for T

source§

fn wrap_with<U, F: FnOnce(Self) -> U>(self, f: F) -> U

Calls the given closure and return the result. Read more
source§

fn with<F: FnOnce(&mut Self)>(self, f: F) -> Self

Calls the given closure on self.
source§

fn try_with<E, F>(self, f: F) -> Result<Self, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Calls the given closure on self.
source§

fn with_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure if condition == true.