GuestErrorContext

Trait GuestErrorContext 

Source
pub trait GuestErrorContext {
    type Ok;

    // Required methods
    fn context(self, ctx: impl Into<String>) -> Result<Self::Ok>;
    fn context_and_code(
        self,
        ec: ErrorCode,
        ctx: impl Into<String>,
    ) -> Result<Self::Ok>;
    fn with_context<S: Into<String>>(
        self,
        ctx: impl FnOnce() -> S,
    ) -> Result<Self::Ok>;
    fn with_context_and_code<S: Into<String>>(
        self,
        ec: ErrorCode,
        ctx: impl FnOnce() -> S,
    ) -> Result<Self::Ok>;
}
Expand description

Extension trait to add context to Option<T> and Result<T, E> types in guest code, converting them to Result<T, HyperlightGuestError>.

This is similar to anyhow::Context.

Required Associated Types§

Required Methods§

Source

fn context(self, ctx: impl Into<String>) -> Result<Self::Ok>

Adds context to the error if self is None or Err.

Source

fn context_and_code( self, ec: ErrorCode, ctx: impl Into<String>, ) -> Result<Self::Ok>

Adds context and a specific error code to the error if self is None or Err.

Source

fn with_context<S: Into<String>>( self, ctx: impl FnOnce() -> S, ) -> Result<Self::Ok>

Lazily adds context to the error if self is None or Err.

This is useful if constructing the context message is expensive.

Source

fn with_context_and_code<S: Into<String>>( self, ec: ErrorCode, ctx: impl FnOnce() -> S, ) -> Result<Self::Ok>

Lazily adds context and a specific error code to the error if self is None or Err.

This is useful if constructing the context message is expensive.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> GuestErrorContext for Option<T>

Source§

type Ok = T

Source§

fn context(self, ctx: impl Into<String>) -> Result<T>

Source§

fn context_and_code(self, ec: ErrorCode, ctx: impl Into<String>) -> Result<T>

Source§

fn with_context<S: Into<String>>(self, ctx: impl FnOnce() -> S) -> Result<T>

Source§

fn with_context_and_code<S: Into<String>>( self, ec: ErrorCode, ctx: impl FnOnce() -> S, ) -> Result<Self::Ok>

Source§

impl<T, E: Debug> GuestErrorContext for Result<T, E>

Source§

type Ok = T

Source§

fn context(self, ctx: impl Into<String>) -> Result<T>

Source§

fn context_and_code(self, ec: ErrorCode, ctx: impl Into<String>) -> Result<T>

Source§

fn with_context<S: Into<String>>(self, ctx: impl FnOnce() -> S) -> Result<T>

Source§

fn with_context_and_code<S: Into<String>>( self, ec: ErrorCode, ctx: impl FnOnce() -> S, ) -> Result<T>

Implementors§