pub struct Envelope<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: Serialize> Envelope<T>
impl<T: Serialize> Envelope<T>
Sourcepub fn success(schema_version: impl Into<String>, data: T) -> Self
pub fn success(schema_version: impl Into<String>, data: T) -> Self
Build a successful envelope.
Sourcepub fn failure(schema_version: impl Into<String>, error: EnvelopeError) -> Self
pub fn failure(schema_version: impl Into<String>, error: EnvelopeError) -> Self
Build a failure envelope with no payload.
Sourcepub fn with_warning(self, warning: impl Into<String>) -> Self
pub fn with_warning(self, warning: impl Into<String>) -> Self
Append a single warning to the envelope.
Sourcepub fn with_warnings<I, S>(self, warnings: I) -> Self
pub fn with_warnings<I, S>(self, warnings: I) -> Self
Append multiple warnings to the envelope.
Trait Implementations§
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