pub struct Envelope<T>where
T: Serialize,{
pub schema_version: String,
pub ok: bool,
pub data: Option<T>,
pub warnings: Vec<String>,
pub error: Option<EnvelopeError>,
}Expand description
Envelope shared by every JSON-emitting subcommand.
The shape is intentionally narrow: schema_version pins the wire contract,
ok is a boolean success flag, data carries the per-subcommand payload,
warnings collects non-fatal diagnostics (so JSON consumers see what text
mode would print to stderr), and error carries a structured failure.
Fields§
§schema_version: String§ok: bool§data: Option<T>§warnings: Vec<String>§error: Option<EnvelopeError>Implementations§
Source§impl<T> Envelope<T>where
T: Serialize,
impl<T> Envelope<T>where
T: Serialize,
Sourcepub fn success(schema_version: impl Into<String>, data: T) -> Envelope<T>
pub fn success(schema_version: impl Into<String>, data: T) -> Envelope<T>
Build a successful envelope.
Sourcepub fn failure(
schema_version: impl Into<String>,
error: EnvelopeError,
) -> Envelope<T>
pub fn failure( schema_version: impl Into<String>, error: EnvelopeError, ) -> Envelope<T>
Build a failure envelope with no payload.
Sourcepub fn with_warning(self, warning: impl Into<String>) -> Envelope<T>
pub fn with_warning(self, warning: impl Into<String>) -> Envelope<T>
Append a single warning to the envelope.
Sourcepub fn with_warnings<I, S>(self, warnings: I) -> Envelope<T>
pub fn with_warnings<I, S>(self, warnings: I) -> Envelope<T>
Append multiple warnings to the envelope.
Trait Implementations§
Source§impl<T> Serialize for Envelope<T>where
T: Serialize,
impl<T> Serialize for Envelope<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl<T> Freeze for Envelope<T>where
T: Freeze,
impl<T> RefUnwindSafe for Envelope<T>where
T: RefUnwindSafe,
impl<T> Send for Envelope<T>where
T: Send,
impl<T> Sync for Envelope<T>where
T: Sync,
impl<T> Unpin for Envelope<T>where
T: Unpin,
impl<T> UnsafeUnpin for Envelope<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Envelope<T>where
T: UnwindSafe,
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