pub struct Coroutine<'a>(/* private fields */);
Expand description
Context object that represents the currently executing coroutine.
Implementations§
Source§impl<'a> Coroutine<'a>
impl<'a> Coroutine<'a>
Sourcepub fn wrap<R, E>(&self) -> CoroutineHandler<R, E>
pub fn wrap<R, E>(&self) -> CoroutineHandler<R, E>
Provides a Coroutine
handler to asynchronous operation.
The CoroutineHandler has trait the Handler
, that type of Handler::Output
is io::Result<R>
.
§Examples
use asyncio::{IoContext, AsIoContext, Stream};
use asyncio::ip::{IpProtocol, Tcp, TcpSocket};
let ctx = &IoContext::new().unwrap();
IoContext::spawn(ctx, |coro| {
let ctx = coro.as_ctx();
let mut soc = TcpSocket::new(ctx, Tcp::v4()).unwrap();
let mut buf = [0; 256];
let size = soc.async_read_some(&mut buf, coro.wrap()).unwrap();
});
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Coroutine<'a>
impl<'a> !RefUnwindSafe for Coroutine<'a>
impl<'a> !Send for Coroutine<'a>
impl<'a> !Sync for Coroutine<'a>
impl<'a> Unpin for Coroutine<'a>
impl<'a> !UnwindSafe for Coroutine<'a>
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