Skip to main content

MiddlewareResult

Struct MiddlewareResult 

Source
pub struct MiddlewareResult<T> { /* private fields */ }
Expand description

What a Middleware returns.

§Examples

use moonlit_pdk::{MiddlewareResult, NoOutput};

let ok = MiddlewareResult::ok(NoOutput {}).with_warning("`force` is deprecated");
assert!(ok.is_success());
assert_eq!(ok.warnings(), ["`force` is deprecated"]);

let failed: MiddlewareResult<NoOutput> = MiddlewareResult::failure("tag already exists");
assert!(!failed.is_success());
assert_eq!(failed.error_message(), Some("tag already exists"));

Implementations§

Source§

impl<T: Serialize> MiddlewareResult<T>

Source

pub fn ok(output: T) -> Self

A successful outcome carrying the middleware’s typed output. Use NoOutput for middlewares that publish nothing.

Source§

impl<T> MiddlewareResult<T>

Source

pub fn failure(msg: impl Into<String>) -> Self

A failed outcome; carries no output.

Source

pub fn with_warning(self, msg: impl Into<String>) -> Self

Source

pub fn is_success(&self) -> bool

Whether the middleware succeeded. Useful in sdk::testing unit tests.

Source

pub fn error_message(&self) -> Option<&str>

The failure message, if this result is a failure.

Source

pub fn warnings(&self) -> &[String]

Warnings attached to this result.

Source§

impl<T: Serialize> MiddlewareResult<T>

Source

pub fn into_wit(self) -> MiddlewareResult

Convert to the WIT record. The typed output is serialized to a JSON object and spread into the (key, json-text) output list (the field names become the map keys, so steps.NAME.outputs.<field> resolves). A non-object output or a serialization error degrades to a loud failure.

Auto Trait Implementations§

§

impl<T> Freeze for MiddlewareResult<T>
where Option<T>: Freeze,

§

impl<T> RefUnwindSafe for MiddlewareResult<T>

§

impl<T> Send for MiddlewareResult<T>
where Option<T>: Send,

§

impl<T> Sync for MiddlewareResult<T>
where Option<T>: Sync,

§

impl<T> Unpin for MiddlewareResult<T>
where Option<T>: Unpin,

§

impl<T> UnsafeUnpin for MiddlewareResult<T>
where Option<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for MiddlewareResult<T>
where Option<T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Resource for T
where T: 'static,

Source§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.