pub struct Context<'a> { /* private fields */ }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,
pub fn with_context<'b>(context: &'a Context<'_>) -> 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.
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>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> !RefUnwindSafe for Context<'a>
impl<'a> Send for Context<'a>
impl<'a> Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> !UnwindSafe for Context<'a>
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
Mutably borrows from an owned value. Read more