use tachyonix;
use futures_executor::{block_on, ThreadPool};
let pool = ThreadPool::new().unwrap();
let (mut s, mut r) = tachyonix::channel(3);
block_on( async move {
pool.spawn_ok( async move {
assert_eq!(s.send("Hello").await, Ok(()));
});
assert_eq!(r.recv().await, Ok("Hello"));
});
USAGE:
rsre FILE/DIRECTORY NEW_FULL_NAME
OPTIONS:
-h, --help Print help information
-V, --version Print version information
# with mv
mv ../../foo/bar/bat/foo.txt ../../foo/bar/bat/bar.txt
# with rsre
rsre ../../foo/bar/bat/foo.txt bar.txt
panic,当然我们也不想花太多时间处理意外错误。这就是本项目的用途,你可以保留意外错误,直到以后再担心它们。use exun::*;
fn foo(num: &str) -> Result<i32, RawUnexpected> {
// 使用 `unexpect` 表示我们预计不会发生这个错误
let num = num.parse::<i32>().unexpect()?;
Ok(num)
}
use std::error::Error;
use std::fmt::{self, Display};
use exun::*;
#[derive(Debug)]
struct NoNumberError;
impl Display for NoNumberError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "no number provided")
}
}
impl Error for NoNumberError {}
fn foo(num: Option<&str>) -> Result<i32, Expect<NoNumberError>> {
let num = num.ok_or(NoNumberError)?; // 预计这可能会返回一个错误
let num = num.parse::<i32>().unexpect()?; // 但我们认为这个数字是可以解析的
Ok(num)
}
use std::error::Error;
use std::fmt::{self, Display};
use std::num::ParseIntError;
use exun::*;
#[derive(Debug)]
struct NoNumberError;
impl Display for NoNumberError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "no number provided")
}
}
impl Error for NoNumberError {}
fn foo(num: Option<&str>) -> Result<i32, Exun<&str, ParseIntError>> {
// 预计可能不会得到一个数字,所以这样处理
let num = match num {
Some(num) => num,
None => return Err(Expected("no number provided")),
};
// 但是,我们希望这个数字是可以解析的
match num.parse() {
Ok(int) => Ok(int),
Err(e) => Err(Unexpected(e))
}
}
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。