pub struct Context { /* private fields */ }Expand description
A map of arbitrary JSON values, for use by plugins.
Context makes use of DashMap under the hood which tries to handle concurrency
by allowing concurrency across threads without requiring locking. This is great
for usability but could lead to surprises when updates are highly contested.
Within the router, contention is likely to be highest within plugins which
provide crate::services::SubgraphRequest or
crate::services::SubgraphResponse processing. At such times,
plugins should restrict themselves to the Context::get and Context::upsert
functions to minimise the possibility of mis-sequenced updates.
Implementationsยง
Sourceยงimpl Context
 
impl Context
Sourcepub fn extensions(&self) -> &ExtensionsMutex
 
pub fn extensions(&self) -> &ExtensionsMutex
Returns extensions of the context.
You can use Extensions to pass data between plugins that is not serializable. Such data is not accessible from Rhai or co-processoers.
It is CRITICAL to avoid holding on to the mutex guard for too long, particularly across async calls. Doing so may cause performance degradation or even deadlocks.
See related clippy lint for examples: https://rust-lang.github.io/rust-clippy/master/index.html#/await_holding_lock
Sourcepub fn contains_key<K>(&self, key: K) -> bool
 
pub fn contains_key<K>(&self, key: K) -> bool
Returns true if the context contains a value for the specified key.
Sourcepub fn get<K, V>(&self, key: K) -> Result<Option<V>, BoxError>
 
pub fn get<K, V>(&self, key: K) -> Result<Option<V>, BoxError>
Get a value from the context using the provided key.
Semantics:
- If the operation fails, thatโs because we canโt deserialize the value.
 - If the operation succeeds, the value is an 
Option. 
Sourcepub fn insert<K, V>(&self, key: K, value: V) -> Result<Option<V>, BoxError>
 
pub fn insert<K, V>(&self, key: K, value: V) -> Result<Option<V>, BoxError>
Insert a value int the context using the provided key and value.
Semantics:
- If the operation fails, then the pair has not been inserted.
 - If the operation succeeds, the result is the old value as an 
Option. 
Sourcepub fn insert_json_value<K>(&self, key: K, value: Value) -> Option<Value>
 
pub fn insert_json_value<K>(&self, key: K, value: Value) -> Option<Value>
Insert a value in the context using the provided key and value.
Semantics: the result is the old value as an Option.
Sourcepub fn get_json_value<K>(&self, key: K) -> Option<Value>
 
pub fn get_json_value<K>(&self, key: K) -> Option<Value>
Get a json value from the context using the provided key.
Sourcepub fn upsert<K, V>(
    &self,
    key: K,
    upsert: impl FnOnce(V) -> V,
) -> Result<(), BoxError>
 
pub fn upsert<K, V>( &self, key: K, upsert: impl FnOnce(V) -> V, ) -> Result<(), BoxError>
Upsert a value in the context using the provided key and resolving function.
The resolving function must yield a value to be used in the context. It is provided with the current value to use in evaluating which value to yield.
Semantics:
- If the operation fails, then the pair has not been inserted (or a current value updated).
 - If the operation succeeds, the pair have either updated an existing value or been inserted.
 
Trait Implementationsยง
Sourceยงimpl<'de> Deserialize<'de> for Context
 
impl<'de> Deserialize<'de> for Context
Sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,
 
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,
Auto Trait Implementationsยง
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
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> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Sourceยงimpl<T> FromBase64 for Twhere
    T: for<'de> Deserialize<'de>,
 
impl<T> FromBase64 for Twhere
    T: for<'de> Deserialize<'de>,
Sourceยงimpl<T> FutureExt for T
 
impl<T> FutureExt for T
Sourceยงfn with_context(self, otel_cx: Context) -> WithContext<Self>
 
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Sourceยงfn with_current_context(self) -> WithContext<Self>
 
fn with_current_context(self) -> WithContext<Self>
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> 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 moreSourceยงimpl<T> IntoRequest<T> for T
 
impl<T> IntoRequest<T> for T
Sourceยงfn into_request(self) -> Request<T>
 
fn into_request(self) -> Request<T>
T in a tonic::RequestSourceยงimpl<T> Paint for Twhere
    T: ?Sized,
 
impl<T> Paint for Twhere
    T: ?Sized,
Sourceยงfn fg(&self, value: Color) -> Painted<&T>
 
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
ยงExample
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Sourceยงfn bright_black(&self) -> Painted<&T>
 
fn bright_black(&self) -> Painted<&T>
Sourceยงfn bright_red(&self) -> Painted<&T>
 
fn bright_red(&self) -> Painted<&T>
Sourceยงfn bright_green(&self) -> Painted<&T>
 
fn bright_green(&self) -> Painted<&T>
Sourceยงfn bright_yellow(&self) -> Painted<&T>
 
fn bright_yellow(&self) -> Painted<&T>
Sourceยงfn bright_blue(&self) -> Painted<&T>
 
fn bright_blue(&self) -> Painted<&T>
Sourceยงfn bright_magenta(&self) -> Painted<&T>
 
fn bright_magenta(&self) -> Painted<&T>
Sourceยงfn bright_cyan(&self) -> Painted<&T>
 
fn bright_cyan(&self) -> Painted<&T>
Sourceยงfn bright_white(&self) -> Painted<&T>
 
fn bright_white(&self) -> Painted<&T>
Sourceยงfn bg(&self, value: Color) -> Painted<&T>
 
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
ยงExample
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Sourceยงfn on_primary(&self) -> Painted<&T>
 
fn on_primary(&self) -> Painted<&T>
Sourceยงfn on_magenta(&self) -> Painted<&T>
 
fn on_magenta(&self) -> Painted<&T>
Sourceยงfn on_bright_black(&self) -> Painted<&T>
 
fn on_bright_black(&self) -> Painted<&T>
Sourceยงfn on_bright_red(&self) -> Painted<&T>
 
fn on_bright_red(&self) -> Painted<&T>
Sourceยงfn on_bright_green(&self) -> Painted<&T>
 
fn on_bright_green(&self) -> Painted<&T>
Sourceยงfn on_bright_yellow(&self) -> Painted<&T>
 
fn on_bright_yellow(&self) -> Painted<&T>
Sourceยงfn on_bright_blue(&self) -> Painted<&T>
 
fn on_bright_blue(&self) -> Painted<&T>
Sourceยงfn on_bright_magenta(&self) -> Painted<&T>
 
fn on_bright_magenta(&self) -> Painted<&T>
Sourceยงfn on_bright_cyan(&self) -> Painted<&T>
 
fn on_bright_cyan(&self) -> Painted<&T>
Sourceยงfn on_bright_white(&self) -> Painted<&T>
 
fn on_bright_white(&self) -> Painted<&T>
Sourceยงfn attr(&self, value: Attribute) -> Painted<&T>
 
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
ยงExample
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Sourceยงfn rapid_blink(&self) -> Painted<&T>
 
fn rapid_blink(&self) -> Painted<&T>
Sourceยงfn quirk(&self, value: Quirk) -> Painted<&T>
 
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
ยงExample
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Sourceยงfn clear(&self) -> Painted<&T>
 ๐Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Sourceยงfn whenever(&self, value: Condition) -> Painted<&T>
 
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
ยงExample
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Sourceยงimpl<T> Pointable for T
 
impl<T> Pointable for T
Sourceยงimpl<T> PolicyExt for Twhere
    T: ?Sized,
 
impl<T> PolicyExt for Twhere
    T: ?Sized,
Sourceยงimpl<T> Serialize for T
 
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
Sourceยงimpl<T> ServiceExt for T
 
impl<T> ServiceExt for T
Sourceยงfn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
    Self: Sized,
 
fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
    Self: Sized,
Sourceยงfn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
    Self: Sized,
 
fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
    Self: Sized,
Sourceยงfn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>where
    Self: Sized,
 
fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>where
    Self: Sized,
Sourceยงfn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
    Self: Sized,
 
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
    Self: Sized,
Sourceยงfn compression(self) -> Compression<Self>where
    Self: Sized,
 
fn compression(self) -> Compression<Self>where
    Self: Sized,
Sourceยงfn decompression(self) -> Decompression<Self>where
    Self: Sized,
 
fn decompression(self) -> Decompression<Self>where
    Self: Sized,
Sourceยงfn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
    Self: Sized,
 
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
    Self: Sized,
Sourceยงfn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
    Self: Sized,
 
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
    Self: Sized,
Sourceยงfn follow_redirects(self) -> FollowRedirect<Self>where
    Self: Sized,
 
fn follow_redirects(self) -> FollowRedirect<Self>where
    Self: Sized,
Sourceยงfn sensitive_headers(
    self,
    headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
    Self: Sized,
 
fn sensitive_headers(
    self,
    headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
    Self: Sized,
Sourceยงfn sensitive_request_headers(
    self,
    headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
    Self: Sized,
 
fn sensitive_request_headers(
    self,
    headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
    Self: Sized,
Sourceยงfn sensitive_response_headers(
    self,
    headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
    Self: Sized,
 
fn sensitive_response_headers(
    self,
    headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
    Self: Sized,
Sourceยงfn override_request_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetRequestHeader<Self, M>where
    Self: Sized,
 
fn override_request_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetRequestHeader<Self, M>where
    Self: Sized,
Sourceยงfn append_request_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetRequestHeader<Self, M>where
    Self: Sized,
 
fn append_request_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetRequestHeader<Self, M>where
    Self: Sized,
Sourceยงfn insert_request_header_if_not_present<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetRequestHeader<Self, M>where
    Self: Sized,
 
fn insert_request_header_if_not_present<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetRequestHeader<Self, M>where
    Self: Sized,
Sourceยงfn override_response_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetResponseHeader<Self, M>where
    Self: Sized,
 
fn override_response_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetResponseHeader<Self, M>where
    Self: Sized,
Sourceยงfn append_response_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetResponseHeader<Self, M>where
    Self: Sized,
 
fn append_response_header<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetResponseHeader<Self, M>where
    Self: Sized,
Sourceยงfn insert_response_header_if_not_present<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetResponseHeader<Self, M>where
    Self: Sized,
 
fn insert_response_header_if_not_present<M>(
    self,
    header_name: HeaderName,
    make: M,
) -> SetResponseHeader<Self, M>where
    Self: Sized,
Sourceยงfn set_request_id<M>(
    self,
    header_name: HeaderName,
    make_request_id: M,
) -> SetRequestId<Self, M>where
    Self: Sized,
    M: MakeRequestId,
 
fn set_request_id<M>(
    self,
    header_name: HeaderName,
    make_request_id: M,
) -> SetRequestId<Self, M>where
    Self: Sized,
    M: MakeRequestId,
Sourceยงfn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
    Self: Sized,
    M: MakeRequestId,
 
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
    Self: Sized,
    M: MakeRequestId,
x-request-id as the header name. Read moreSourceยงfn propagate_request_id(
    self,
    header_name: HeaderName,
) -> PropagateRequestId<Self>where
    Self: Sized,
 
fn propagate_request_id(
    self,
    header_name: HeaderName,
) -> PropagateRequestId<Self>where
    Self: Sized,
Sourceยงfn propagate_x_request_id(self) -> PropagateRequestId<Self>where
    Self: Sized,
 
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
    Self: Sized,
x-request-id as the header name. Read moreSourceยงfn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
    Self: Sized,
 
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
    Self: Sized,
500 Internal Server responses. Read moreSourceยงfn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
    Self: Sized,
 
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
    Self: Sized,
413 Payload Too Large responses. Read moreSourceยงfn trim_trailing_slash(self) -> NormalizePath<Self>where
    Self: Sized,
 
fn trim_trailing_slash(self) -> NormalizePath<Self>where
    Self: Sized,
Sourceยงfn append_trailing_slash(self) -> NormalizePath<Self>where
    Self: Sized,
 
fn append_trailing_slash(self) -> NormalizePath<Self>where
    Self: Sized,
Sourceยงimpl<C> SignWithKey<String> for Cwhere
    C: ToBase64,
 
impl<C> SignWithKey<String> for Cwhere
    C: ToBase64,
fn sign_with_key(self, key: &impl SigningAlgorithm) -> Result<String, Error>
Sourceยงimpl<T> Variant for T
 
impl<T> Variant for T
Sourceยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
 
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Variant trait object to &mut dyn Any.Sourceยงfn as_boxed_any(self: Box<T>) -> Box<dyn Any>
 
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Variant trait object to Box<dyn Any>.