#[repr(C)]pub struct XabiFuture {
pub size: usize,
pub abi_version: u32,
pub instance: *mut c_void,
pub poll: unsafe extern "C" fn(*mut c_void, *const XabiWaker, *mut XabiResult) -> i32,
pub release: unsafe extern "C" fn(*mut c_void),
}Expand description
Future handle returned by async xabi vtable methods.
Hosts poll this handle through XabiFutureHandle. Exporters can construct a
handle from a Rust future with XabiFuture::from_result_bytes.
Fields§
§size: usizeSize of this structure in bytes.
abi_version: u32ABI version for this structure.
instance: *mut c_voidOpaque future state pointer.
poll: unsafe extern "C" fn(*mut c_void, *const XabiWaker, *mut XabiResult) -> i32Poll the future.
release: unsafe extern "C" fn(*mut c_void)Release the future state.
Implementations§
Source§impl XabiFuture
impl XabiFuture
Sourcepub const ABI_VERSION: u32 = ABI_VERSION
pub const ABI_VERSION: u32 = ABI_VERSION
ABI version expected by this structure.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty invalid future placeholder.
let future = xabi::XabiFuture::empty();
assert!(future.validate().is_err());Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the future layout and required fields.
let future = xabi::XabiFuture::from_result_bytes(async {
Ok::<_, xabi::Error>(b"ready".to_vec())
});
future.validate().unwrap();
unsafe { (future.release)(future.instance) };Sourcepub fn from_result_bytes<F, E>(future: F) -> Self
pub fn from_result_bytes<F, E>(future: F) -> Self
Convert a Rust future returning bytes into an xabi future handle.
The future must be Send so host executors may move the foreign future
between worker threads.
use std::future::Future;
use std::pin::pin;
use std::sync::Arc;
use std::task::{Context, Poll, Wake, Waker};
struct Noop;
impl Wake for Noop {
fn wake(self: Arc<Self>) {}
}
let future = xabi::XabiFuture::from_result_bytes(async {
Ok::<_, xabi::Error>(b"hello".to_vec())
});
let mut future = pin!(xabi::XabiFutureHandle::new(future).unwrap());
let waker = Waker::from(Arc::new(Noop));
let mut cx = Context::from_waker(&waker);
match Future::poll(future.as_mut(), &mut cx) {
Poll::Ready(Ok(bytes)) => assert_eq!(bytes, b"hello"),
other => panic!("unexpected poll result: {other:?}"),
}Sourcepub fn from_result_value<F, T, E>(future: F) -> Self
pub fn from_result_value<F, T, E>(future: F) -> Self
Convert a Rust future returning an xabi value into an ABI future handle.
The success value is encoded with XabiType::into_payload.
Trait Implementations§
impl Send for XabiFuture
Auto Trait Implementations§
impl !Sync for XabiFuture
impl Freeze for XabiFuture
impl RefUnwindSafe for XabiFuture
impl Unpin for XabiFuture
impl UnsafeUnpin for XabiFuture
impl UnwindSafe for XabiFuture
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