pub struct Receiver<T> { /* private fields */ }Expand description
Receiver for one-shot value transfer
Implements Future directly, allowing direct .await usage on both owned values and mutable references
一次性值传递的接收器
直接实现了 Future,允许对拥有的值和可变引用都直接使用 .await
§Examples
§Basic usage
use lite_sync::oneshot::generic::Sender;
let (sender, receiver) = Sender::<String>::new();
tokio::spawn(async move {
sender.send("Hello, World!".to_string()).unwrap();
});
// Direct await via Future impl
let message = receiver.await;
assert_eq!(message, "Hello, World!");§Awaiting on mutable reference
use lite_sync::oneshot::generic::Sender;
let (sender, mut receiver) = Sender::<i32>::new();
tokio::spawn(async move {
sender.send(42).unwrap();
});
// Can also await on &mut receiver
let value = (&mut receiver).await;
assert_eq!(value, 42);Implementations§
Trait Implementations§
Source§impl<T> Future for Receiver<T>
Direct Future implementation for Receiver
impl<T> Future for Receiver<T>
Direct Future implementation for Receiver
This allows both receiver.await and (&mut receiver).await to work
Optimized implementation:
- Fast path: Immediate return if value already sent (no allocation)
- Slow path: Direct waker registration (no Box allocation, just copy two pointers)
- No intermediate future state needed
为 Receiver 直接实现 Future
这允许 receiver.await 和 (&mut receiver).await 都能工作
优化实现:
- 快速路径:如值已发送则立即返回(无分配)
- 慢速路径:直接注册 waker(无 Box 分配,只复制两个指针)
- 无需中间 future 状态
impl<T> Unpin for Receiver<T>
Auto Trait Implementations§
impl<T> Freeze for Receiver<T>
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T>where
T: Send,
impl<T> Sync for Receiver<T>where
T: Send,
impl<T> !UnwindSafe for Receiver<T>
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
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more