本文簡要介紹rust語言中 core::task::Poll.map_err
的用法。
用法
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>>>
,保持所有其他變體不變。
此函數可用於在處理錯誤時傳遞成功的結果。
例子
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))));
相關用法
- Rust Poll.map_err用法及代碼示例
- Rust Poll.map_ok用法及代碼示例
- Rust Poll.map用法及代碼示例
- Rust Poll.is_ready用法及代碼示例
- Rust Poll.ready用法及代碼示例
- Rust Poll.is_pending用法及代碼示例
- Rust Pointer用法及代碼示例
- Rust PoisonError用法及代碼示例
- Rust PoisonError.into_inner用法及代碼示例
- Rust PanicInfo.payload用法及代碼示例
- Rust Path.components用法及代碼示例
- Rust PathBuf.with_capacity用法及代碼示例
- Rust Peekable.peek用法及代碼示例
- Rust Path.is_symlink用法及代碼示例
- Rust Path.canonicalize用法及代碼示例
- Rust PartialOrd.partial_cmp用法及代碼示例
- Rust Path.is_relative用法及代碼示例
- Rust Path.file_stem用法及代碼示例
- Rust PermissionsExt.set_mode用法及代碼示例
- Rust Path.to_string_lossy用法及代碼示例
- Rust Path.display用法及代碼示例
- Rust PathBuf.into_os_string用法及代碼示例
- Rust Peekable.next_if用法及代碼示例
- Rust PanicInfo用法及代碼示例
- Rust PathBuf.pop用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 core::task::Poll.map_err。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。