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> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>where F: From<E>,
source§fn from_residual(x: Result<Infallible, E>) -> Poll<Option<Result<T, F>>>
fn from_residual(x: Result<Infallible, E>) -> Poll<Option<Result<T, F>>>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)从兼容的
Residual
类型构造类型。 Read moresource§impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>where F: From<E>,
source§fn from_residual(x: Result<Infallible, E>) -> Poll<Result<T, F>>
fn from_residual(x: Result<Infallible, E>) -> Poll<Result<T, F>>
🔬This is a nightly-only experimental API. (
try_trait_v2
#84277)从兼容的
Residual
类型构造类型。 Read moresource§impl<T> PartialOrd<Poll<T>> for Poll<T>where
T: PartialOrd<T>,
impl<T> PartialOrd<Poll<T>> for Poll<T>where T: PartialOrd<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§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)impl<T> Copy for Poll<T>where T: Copy,
impl<T> Eq for Poll<T>where T: Eq,
impl<T> StructuralEq for Poll<T>
impl<T> StructuralPartialEq for Poll<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Poll<T>where T: RefUnwindSafe,
impl<T> Send for Poll<T>where T: Send,
impl<T> Sync for Poll<T>where T: Sync,
impl<T> Unpin for Poll<T>where T: Unpin,
impl<T> UnwindSafe for Poll<T>where T: UnwindSafe,
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
从拥有的值中借用。 Read more