pub struct Context { /* private fields */ }Expand description
上下文:主链路元数据 + 取消/超时 + 父子 + TypeMap。
内部为 Arc 包装,Clone 仅增加引用计数。
Implementations§
Source§impl Context
impl Context
pub fn root() -> Context
pub fn with_request_id(request_id: impl AsRef<str>) -> Context
pub fn child(&self) -> Context
pub fn with_timeout(&self, d: Duration) -> Context
pub fn with_timeout_ms(&self, ms: u64) -> Context
pub fn with_deadline(&self, deadline: Instant) -> Context
pub fn with_task(&self, timeout_ms: Option<u64>) -> Context
pub fn with_trace_id(&self, trace_id: impl AsRef<str>) -> Context
pub fn with_user_id(&self, user_id: impl AsRef<str>) -> Context
pub fn with_tenant_id(&self, tenant_id: impl AsRef<str>) -> Context
pub fn with_device_id(&self, device_id: impl AsRef<str>) -> Context
pub fn with_platform(&self, platform: impl AsRef<str>) -> Context
pub fn with_session_id(&self, session_id: impl AsRef<str>) -> Context
pub fn insert_data<T>(&self, value: T) -> Context
pub fn get_data<T>(&self) -> Option<&T>where
T: 'static,
pub fn remove_data<T>(&self) -> (Context, Option<T>)
pub fn with_actor(&self, actor: ActorContext) -> Context
pub fn actor(&self) -> Option<&ActorContext>
pub fn with_audit(&self, audit: AuditContext) -> Context
pub fn audit(&self) -> Option<&AuditContext>
pub fn cancel(&self)
pub fn is_cancelled(&self) -> bool
pub async fn cancelled(&self)
pub async fn run<F, T>(&self, fut: F) -> Option<T>where
F: Future<Output = T>,
pub fn remaining_time(&self) -> Option<Duration>
pub fn deadline(&self) -> Option<Instant>
pub fn request_id(&self) -> &str
pub fn trace_id(&self) -> &str
pub fn user_id(&self) -> Option<&str>
pub fn tenant_id(&self) -> Option<&str>
pub fn device_id(&self) -> Option<&str>
pub fn platform(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Trait Implementations§
Source§impl AsRef<Context> for Context
使 &Context 可直接用于 set_context_metadata(request, ctx) 等需要 AsRef<Context> 的 API。
impl AsRef<Context> for Context
使 &Context 可直接用于 set_context_metadata(request, ctx) 等需要 AsRef<Context> 的 API。
Source§impl ContextExt for Context
impl ContextExt for Context
fn ensure_not_cancelled(&self) -> Result<(), ContextError>
fn check_cancelled(&self) -> Result<(), ContextError>
Auto Trait Implementations§
impl !RefUnwindSafe for Context
impl !UnwindSafe for Context
impl Freeze for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> 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> ⓘ
Converts
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> ⓘ
Converts
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>
Wrap the input message
T in a tonic::Request