pub enum Poll<T> {
Ready(T),
Pending,
}
Expand description
指示值是否可用,或者当前任务是否已安排为接收唤醒。
Variants§
Implementations§
source§impl<T> Poll<T>
impl<T> Poll<T>
sourcepub fn map<U, F>(self, f: F) -> Poll<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Poll<U>where F: FnOnce(T) -> U,
通过将函数应用于包含的值,Maps 从 Poll<T>
到 Poll<U>
。
Examples
将 Poll<String>
转换为 Poll<usize>
,消耗原始值:
let poll_some_string = Poll::Ready(String::from("Hello, World!"));
// `Poll::map` 会按值获取 self,消耗 `poll_some_string`
let poll_some_len = poll_some_string.map(|s| s.len());
assert_eq!(poll_some_len, Poll::Ready(13));
Runsource§impl<T, E> Poll<Result<T, E>>
impl<T, E> Poll<Result<T, E>>
source§impl<T, E> Poll<Option<Result<T, E>>>
impl<T, E> Poll<Option<Result<T, E>>>
1.51.0 · sourcepub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>where
F: FnOnce(T) -> U,
pub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>where F: FnOnce(T) -> U,
1.51.0 · sourcepub fn map_err<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>where
F: FnOnce(E) -> U,
pub fn map_err<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>where F: FnOnce(E) -> U,
通过对包含的 Poll::Ready(Some(Err))
值应用一个函数,将 Poll::Ready<Option<Result<T, E>>>
映射为 Poll::Ready<Option<Result<T, F>>>
,让所有其他变体保持不变。
此函数可用于在处理错误时传递成功的结果。
Examples
let res: Poll<Option<Result<u8, _>>> = Poll::Ready(Some("oops".parse()));
let res = res.map_err(|_| 0_u8);
assert_eq!(res, Poll::Ready(Some(Err(0))));
RunTrait Implementations§
source§impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>
impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>
source§fn from_residual(x: Result<Infallible, E>) -> Self
fn from_residual(x: Result<Infallible, E>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)从兼容的
Residual
类型构造类型。 Read moresource§impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>
impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>
source§fn from_residual(x: Result<Infallible, E>) -> Self
fn from_residual(x: Result<Infallible, E>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)从兼容的
Residual
类型构造类型。 Read moresource§impl<T: PartialOrd> PartialOrd<Poll<T>> for Poll<T>
impl<T: PartialOrd> PartialOrd<Poll<T>> for Poll<T>
source§impl<T, E> Try for Poll<Option<Result<T, E>>>
impl<T, E> Try for Poll<Option<Result<T, E>>>
§type Output = Poll<Option<T>>
type Output = Poll<Option<T>>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)当不短路时,
?
产生的值的类型。§type Residual = Result<Infallible, E>
type Residual = Result<Infallible, E>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)source§fn from_output(c: Self::Output) -> Self
fn from_output(c: Self::Output) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)从它的
Output
类型构造类型。 Read moresource§fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)在
?
来决定操作符是应该生成一个值 (因为它返回了 ControlFlow::Continue
),还是将一个值传播回调用者 (因为它返回了 ControlFlow::Break
)。 Read moresource§impl<T, E> Try for Poll<Result<T, E>>
impl<T, E> Try for Poll<Result<T, E>>
§type Output = Poll<T>
type Output = Poll<T>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)当不短路时,
?
产生的值的类型。§type Residual = Result<Infallible, E>
type Residual = Result<Infallible, E>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)source§fn from_output(c: Self::Output) -> Self
fn from_output(c: Self::Output) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)从它的
Output
类型构造类型。 Read moresource§fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)在
?
来决定操作符是应该生成一个值 (因为它返回了 ControlFlow::Continue
),还是将一个值传播回调用者 (因为它返回了 ControlFlow::Break
)。 Read more