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() -> Self
pub fn new() -> Self
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>) -> Self
pub fn of(contexts: Vec<Context>) -> Self
Create a new multi-context builder from the given list of contexts.
sourcepub fn add_context(&mut self, context: Context) -> &mut Self
pub fn add_context(&mut self, context: Context) -> &mut Self
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.