pub enum PromiseStatus {
Fulfilled(Option<Vec<u8>>),
Rejected(Vec<u8>),
}Expand description
Represents the status of a promise, which can either be fulfilled or rejected. This enum is returned by the host VM after executing a promise action.
Variants§
Fulfilled(Option<Vec<u8>>)
The promise completed successfully contains the bytes of the result if any.
Rejected(Vec<u8>)
There was an error executing this promise. The error is represented as bytes, which can be a string or any other serialized form.
Implementations§
Source§impl PromiseStatus
impl PromiseStatus
Sourcepub fn fulfilled(self) -> Vec<u8> ⓘ
pub fn fulfilled(self) -> Vec<u8> ⓘ
Helper function that immediately assumes that the promise has been fulfilled and returns the value.
§Panics
Panics if the promise is not fulfilled.
§Examples
use seda_sdk_rs::{promise::PromiseStatus, bytes::ToBytes};
let promise = PromiseStatus::Fulfilled(Some("Hello, world!".to_bytes().eject()));
assert_eq!(promise.fulfilled(), b"Hello, world!");Sourcepub fn parse<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn parse<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
Parses the fulfilled value of the promise into the desired type.
§Panics
Panics if the promise is not fulfilled.
§Errors
Returns an error if the conversion from bytes to the desired type fails.
§Examples
use seda_sdk_rs::{promise::PromiseStatus, bytes::ToBytes};
use serde_json::Value;
let value = serde_json::json!({"key": "value"});
let promise = PromiseStatus::Fulfilled(Some(serde_json::to_vec(&value).unwrap()));
let parsed: Value = promise.parse().unwrap();
assert_eq!(parsed, value);Trait Implementations§
Source§impl Clone for PromiseStatus
impl Clone for PromiseStatus
Source§fn clone(&self) -> PromiseStatus
fn clone(&self) -> PromiseStatus
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PromiseStatus
impl Debug for PromiseStatus
Source§impl<'de> Deserialize<'de> for PromiseStatus
impl<'de> Deserialize<'de> for PromiseStatus
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PromiseStatus
impl RefUnwindSafe for PromiseStatus
impl Send for PromiseStatus
impl Sync for PromiseStatus
impl Unpin for PromiseStatus
impl UnwindSafe for PromiseStatus
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