Skip to main content

AsyncCompletion

Struct AsyncCompletion 

Source
pub struct AsyncCompletion<T> { /* private fields */ }
Expand description

An async completion handler for FFI callbacks

This type provides a Future that resolves when an async callback completes. It uses Arc<Mutex> internally for thread-safe signaling and waker management. The raw context returned by Self::create is exact-live and one-shot.

Implementations§

Source§

impl<T> AsyncCompletion<T>

Source

pub fn create() -> (AsyncCompletionFuture<T>, SyncCompletionPtr)

Create a new async completion handler and return the context pointer for FFI

Returns a tuple of (future, context_ptr) where:

  • future can be awaited to get the result
  • context_ptr should be passed to the FFI callback
Source

pub unsafe fn complete_ok(context: SyncCompletionPtr, value: T)

Signal successful completion with a value

§Safety

context must be the exact live pointer returned by AsyncCompletion::create. This consumes the callback-owned Arc reference and must be invoked exactly once for that context.

Source

pub unsafe fn complete_err(context: SyncCompletionPtr, error: String)

Signal completion with an error

§Safety

context must be the exact live pointer returned by AsyncCompletion::create. This consumes the callback-owned Arc reference and must be invoked exactly once for that context.

Source

pub unsafe fn complete_with_result( context: SyncCompletionPtr, result: Result<T, String>, )

Signal completion with a result

§Safety

context must be the exact pointer returned by AsyncCompletion::create, its allocation must remain live for this entire call, and foreign code must invoke this completion exactly once and never use the pointer afterward.

The consumed flag only rejects a duplicate call while the allocation is still live. It cannot validate an already-freed, reused, or concurrently invalidated pointer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.