pub enum Envelope<T> {
Success {
version: String,
data: T,
},
Failure {
version: String,
error: OpError,
},
}Expand description
sc-ai-cli response envelope.
Success carries data and writes error as JSON null. Failure carries
OpError and writes data as JSON null. Constructors stamp
ENVELOPE_VERSION. Deserialization keeps the version string from the
input. An ok flag that disagrees with the other field, or an object that
does not have exactly the four keys, is rejected with
DISCRIMINANT_CODE in the error.
Variants§
Success
ok is true and data is T.
Fields
data: TSuccessful payload. JSON null is a valid T such as () or None.
Failure
ok is false and error is the operation error.
Implementations§
Source§impl<T> Envelope<T>
impl<T> Envelope<T>
Sourcepub fn success(data: T) -> Self
pub fn success(data: T) -> Self
Builds a success envelope at ENVELOPE_VERSION.
Sourcepub fn failure(error: OpError) -> Self
pub fn failure(error: OpError) -> Self
Builds a failure envelope at ENVELOPE_VERSION.
Sourcepub fn into_result(self) -> Result<T, OpError>
pub fn into_result(self) -> Result<T, OpError>
Consumes the envelope and returns the success payload or the operation error.
version is not part of the result. A caller that still needs the
contract version reads version before calling this
method.
§Errors
Returns Err when the envelope is the failure case. The error is the
OpError the envelope carried.
§Examples
use sc_command::Envelope;
let envelope = Envelope::success("ready");
assert_eq!(envelope.into_result(), Ok("ready"));