pub struct MultiContextBuilder { /* private fields */ }
Expand description
Contains methods for building a multi-context.
Use this builder if you need to construct a context that has multiple kinds, each representing their own Context. Otherwise, use ContextBuilder.
Obtain an instance of the builder by calling MultiContextBuilder::new; then, call MultiContextBuilder::add_context to add a kind. MultiContextBuilder setters return a reference the same builder, so they can be chained together.
Implementations§
source§impl MultiContextBuilder
impl MultiContextBuilder
sourcepub fn new() -> MultiContextBuilder
pub fn new() -> MultiContextBuilder
Create a new multi-context builder. An empty builder cannot create a valid Context; you must add one or more kinds via MultiContextBuilder::add_context.
If you already have a list of contexts, you can instead use MultiContextBuilder::of.
sourcepub fn of(contexts: Vec<Context>) -> MultiContextBuilder
pub fn of(contexts: Vec<Context>) -> MultiContextBuilder
Create a new multi-context builder from the given list of contexts.
sourcepub fn add_context(&mut self, context: Context) -> &mut MultiContextBuilder
pub fn add_context(&mut self, context: Context) -> &mut MultiContextBuilder
Adds a context to the builder.
It is invalid to add more than one context of the same Kind. This error is detected when you call MultiContextBuilder::build.
If context
is a multi-context, this is equivalent to adding each individual
context.
sourcepub fn build(&self) -> Result<Context, String>
pub fn build(&self) -> Result<Context, String>
Creates a context from the builder’s current properties.
The context is immutable and will not be affected by any subsequent actions on the MultiContextBuilder.
It is possible for a MultiContextBuilder to represent an invalid state. In those
situations, an Err
type will be returned.
If only one context was added to the builder, this method returns that context.
Trait Implementations§
source§impl Default for MultiContextBuilder
impl Default for MultiContextBuilder
source§fn default() -> MultiContextBuilder
fn default() -> MultiContextBuilder
Creates an empty multi-context builder. In this state, a context must be added in order to build successfully.