pub struct TemplateContext {
pub collection: Arc<Collection>,
pub selected_profile: Option<ProfileId>,
pub http_provider: Box<dyn HttpProvider>,
pub overrides: IndexMap<String, ValueTemplate>,
pub prompter: Box<dyn Prompter>,
pub show_sensitive: bool,
pub root_dir: PathBuf,
pub state: RenderGroupState,
}Expand description
A little container struct for all the data that the user can access via
templating. Unfortunately this has to own all data so templating can be
deferred into a task (tokio requires 'static for spawned tasks). If this
becomes a bottleneck, we can Arc some stuff.
One instance of this context applies to all renders in a group (a render group is all the renders for a single request). It’s important to use the same context for an entire request so common profile fields can be cached between components of the request.
This has two different implementations of Context: one for Value and
one for ValueStream. The former is used in most cases, where values are
eagerly evaluated. The latter is used when streams are supported.
Fields§
§collection: Arc<Collection>Entire request collection
selected_profile: Option<ProfileId>ID of the profile whose data should be used for rendering. Generally the caller should check the ID is valid before passing it, to provide a better error to the user if not.
http_provider: Box<dyn HttpProvider>An interface to allow accessing and sending HTTP chained requests
overrides: IndexMap<String, ValueTemplate>Additional profile key=value overrides passed directly from the user. These will be applied to both the root and triggered requests, which is why they are part of the context instead of BuildOptions.
prompter: Box<dyn Prompter>A conduit to ask the user questions
show_sensitive: boolShould sensitive values be shown normally or masked? Enabled for request renders, disabled for previews
root_dir: PathBufDirectory in which to run file system operations. Should be the directory containing the collection file.
state: RenderGroupStateState that should be shared across all renders that use this context. This is meant to be opaque; just use Default::default to initialize.
Trait Implementations§
Source§impl Context<Value> for TemplateContext
impl Context<Value> for TemplateContext
Source§async fn get_field(&self, field: &Identifier) -> Result<Value, RenderError>
async fn get_field(&self, field: &Identifier) -> Result<Value, RenderError>
async. For example, fields can be loaded from a map of nested
templates, in which case the nested template would need to be rendered
before this can be returned.Source§async fn call(
&self,
function_name: &Identifier,
arguments: Arguments<'_, Self>,
) -> Result<Value, RenderError>
async fn call( &self, function_name: &Identifier, arguments: Arguments<'_, Self>, ) -> Result<Value, RenderError>
Source§impl Context<ValueStream> for TemplateContext
impl Context<ValueStream> for TemplateContext
Source§async fn get_field(
&self,
field: &Identifier,
) -> Result<ValueStream, RenderError>
async fn get_field( &self, field: &Identifier, ) -> Result<ValueStream, RenderError>
async. For example, fields can be loaded from a map of nested
templates, in which case the nested template would need to be rendered
before this can be returned.Source§async fn call(
&self,
function_name: &Identifier,
arguments: Arguments<'_, Self>,
) -> Result<ValueStream, RenderError>
async fn call( &self, function_name: &Identifier, arguments: Arguments<'_, Self>, ) -> Result<ValueStream, RenderError>
Auto Trait Implementations§
impl !Freeze for TemplateContext
impl !RefUnwindSafe for TemplateContext
impl !Send for TemplateContext
impl !Sync for TemplateContext
impl Unpin for TemplateContext
impl UnsafeUnpin for TemplateContext
impl !UnwindSafe for TemplateContext
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more