pub struct Context<'a> { /* private fields */ }export-azure only.Expand description
Pipeline execution context.
Do not store Personally-Identifiable Information (PII) in a Context.
It could easily leak in logs or traces.
Implementationsยง
Sourceยงimpl<'a> Context<'a>
impl<'a> Context<'a>
Sourcepub fn with_context<'b>(context: &'a Context<'_>) -> Context<'b>where
'a: 'b,
๐Deprecated since 0.7.0: use to_borrowed() instead
pub fn with_context<'b>(context: &'a Context<'_>) -> Context<'b>where
'a: 'b,
use to_borrowed() instead
Returns a new Context that borrows the type map of the given context.
Once you Context::insert entities the type map is copied.
Sourcepub fn with_value<E>(self, entity: E) -> Context<'a>
pub fn with_value<E>(self, entity: E) -> Context<'a>
Inserts or replaces an entity in the type map and returns Self to allow chaining.
ยงExamples
use typespec_client_core::http::Context;
let context = Context::new()
.with_value(1)
.with_value("test");
assert_eq!(context.value(), Some(&"test"));Sourcepub fn insert<E>(&mut self, entity: E) -> Option<Arc<E>>
pub fn insert<E>(&mut self, entity: E) -> Option<Arc<E>>
Inserts or replaces an entity in the type map. If an entity with the same type was displaced by the insert, it will be returned to the caller.
ยงExamples
use typespec_client_core::http::Context;
use std::sync::Arc;
let mut context = Context::new().with_value("a".to_string());
assert_eq!(context.insert("b".to_string()), Some(Arc::new("a".to_string())));
assert_eq!(context.value(), Some(&"b".to_string()));Sourcepub fn value<E>(&self) -> Option<&E>
pub fn value<E>(&self) -> Option<&E>
Returns a reference of the entity of the specified type signature, if it exists.
If there is no entity with the specific type signature, None is returned instead.
Sourcepub fn into_owned(self) -> Context<'static>
pub fn into_owned(self) -> Context<'static>
Sourcepub fn to_borrowed<'b>(&'a self) -> Context<'b>where
'a: 'b,
pub fn to_borrowed<'b>(&'a self) -> Context<'b>where
'a: 'b,
Returns a new Context that borrows the type map of the given context.
Once you Context::insert entities the type map is copied.