use std::thread;
use tokio::task; // 0.3.4
#[tokio::main]
async fn main() {
thread::spawn(|| {
task::spawn(async {
println!("123");
});
})
.join();
}
Run Code Online (Sandbox Code Playgroud)
编译时我收到警告:
warning: unused `std::result::Result` that must be used
--> src/main.rs:6:5
|
6 | / thread::spawn(|| {
7 | | task::spawn(async {
8 | | println!("123");
9 | | });
10 | | })
11 | | .join();
| |____________^
|
= note: `#[warn(unused_must_use)]` on by default
= note: this `Result` may be an `Err` variant, which should be handled
Run Code Online (Sandbox Code Playgroud)
执行时出现错误: …
是一种初始化可选的方法,如:
bool conditional = true;
boost::optional<int> opt = conditional ? 5 : boost::none;
Run Code Online (Sandbox Code Playgroud)
为什么会出现错误?:
main.cpp:31:31: error: operands to ?: have different types ‘int’ and ‘const boost::none_t’
boost::make_optional(cond ? 5 : boost::none);
| ~~~~~^~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
用简单的if else我可以做到这一点:
boost::optional<int> opt;
if (cond)
opt = 5;
else
opt = boost::none;
Run Code Online (Sandbox Code Playgroud)