rust

What is the difference between `|_| async move {}` and `async move |_| {}`

烂漫一生 提交于 2020-04-10 07:54:27
问题 Let's consider the following examples: main.rs use futures::executor::block_on; use futures::future::{FutureExt, TryFutureExt}; async fn fut1() -> Result<String, u32> { Ok("ok".to_string()) } fn main() { println!("Hello, world!"); match block_on(fut1().and_then(|x| async move { Ok(format!("{} is \"ok\"", x)) })) { Ok(s) => println!("{}", s), Err(u) => println!("{}", u) }; } Cargo.toml [dependencies] futures = "^0.3" I'm asking about the expression |x| async move {} instead of async move |x| {

What is the difference between `|_| async move {}` and `async move |_| {}`

巧了我就是萌 提交于 2020-04-10 07:54:25
问题 Let's consider the following examples: main.rs use futures::executor::block_on; use futures::future::{FutureExt, TryFutureExt}; async fn fut1() -> Result<String, u32> { Ok("ok".to_string()) } fn main() { println!("Hello, world!"); match block_on(fut1().and_then(|x| async move { Ok(format!("{} is \"ok\"", x)) })) { Ok(s) => println!("{}", s), Err(u) => println!("{}", u) }; } Cargo.toml [dependencies] futures = "^0.3" I'm asking about the expression |x| async move {} instead of async move |x| {

MSVC toolchain is not supported. Please use GNU toolchain

无人久伴 提交于 2020-04-10 07:48:08
问题 I was trying to debug Rust in CLion when I was greeted with the aforementioned I updated my toolchain setting to use the suggested default as such: How can I fix this issue and get CLion to be able to debug Rust code? I did some searching but haven't found a simple answer (at at least one I can understand easily). Any help would be greatly appreciated. 回答1: Error message is related about Rust toolchain, if you haven't you need to install gnu toolchain for Rust. > rustup toolchain install

fn foo() -> Result<()> throws “expected 2 type arguments”

江枫思渺然 提交于 2020-04-08 10:09:32
问题 Why isn't Result<()> allowed when compiling this bit of Rust code? Is it a breaking change between Rust editions? fn run() -> Result<()> { let (tx, rx) = channel(); thread::spawn(move || { do_things_with_tx(&exit_tx); }); match exit_rx.recv() { Ok(result) => if let Err(reason) = result { return Err(reason); }, Err(e) => { return Err(e.into()); }, } Ok(()) } The compiler says: error[E0107]: wrong number of type arguments: expected 2, found 1 --> src/main.rs:1000:18 | 1000 | fn run_wifi() ->

fn foo() -> Result<()> throws “expected 2 type arguments”

拜拜、爱过 提交于 2020-04-08 10:06:15
问题 Why isn't Result<()> allowed when compiling this bit of Rust code? Is it a breaking change between Rust editions? fn run() -> Result<()> { let (tx, rx) = channel(); thread::spawn(move || { do_things_with_tx(&exit_tx); }); match exit_rx.recv() { Ok(result) => if let Err(reason) = result { return Err(reason); }, Err(e) => { return Err(e.into()); }, } Ok(()) } The compiler says: error[E0107]: wrong number of type arguments: expected 2, found 1 --> src/main.rs:1000:18 | 1000 | fn run_wifi() ->

fn foo() -> Result<()> throws “expected 2 type arguments”

浪尽此生 提交于 2020-04-08 10:05:42
问题 Why isn't Result<()> allowed when compiling this bit of Rust code? Is it a breaking change between Rust editions? fn run() -> Result<()> { let (tx, rx) = channel(); thread::spawn(move || { do_things_with_tx(&exit_tx); }); match exit_rx.recv() { Ok(result) => if let Err(reason) = result { return Err(reason); }, Err(e) => { return Err(e.into()); }, } Ok(()) } The compiler says: error[E0107]: wrong number of type arguments: expected 2, found 1 --> src/main.rs:1000:18 | 1000 | fn run_wifi() ->

What are the main differences between a Rust Iterator and C++ Iterator? [closed]

最后都变了- 提交于 2020-04-07 16:12:32
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . A typical example of a C++ iterator is a pointer, and can be used to point at an element in a C array like so: int array[] = {1, 2, 3, 4}; int* begin = std::begin(array); //Starting iterator int* end = std::end(array) //Ending iterator for(int* i = begin; i < end; i++) { std::cout

What are the main differences between a Rust Iterator and C++ Iterator? [closed]

 ̄綄美尐妖づ 提交于 2020-04-07 16:12:19
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . A typical example of a C++ iterator is a pointer, and can be used to point at an element in a C array like so: int array[] = {1, 2, 3, 4}; int* begin = std::begin(array); //Starting iterator int* end = std::end(array) //Ending iterator for(int* i = begin; i < end; i++) { std::cout

How to create a Rust struct with string members?

人走茶凉 提交于 2020-04-07 11:12:32
问题 I want the members to be owned by the struct. Sorry for the simple question, but I wasn't able to find an example. I'm looking for the correct declaration of a struct and instantiation examples. 回答1: If the string has to be owned by the struct, then you should use String . Alternatively, you could use an &str with a static lifetime (i.e., the lifetime of the program). For example: struct Foo { bar: String, baz: &'static str, } fn main() { let foo = Foo { bar: "bar".to_string(), baz: "baz", };

Is it possible to write Quake's fast InvSqrt() function in Rust?

爱⌒轻易说出口 提交于 2020-04-07 10:52:06
问题 This is just to satisfy my own curiosity. Is there an implementation of this: float InvSqrt (float x) { float xhalf = 0.5f*x; int i = *(int*)&x; i = 0x5f3759df - (i>>1); x = *(float*)&i; x = x*(1.5f - xhalf*x*x); return x; } in Rust? If it exists, post the code. I tried it and failed. I don't know how to encode the float number using integer format. Here is my attempt: fn main() { println!("Hello, world!"); println!("sqrt1: {}, ",sqrt2(100f64)); } fn sqrt1(x: f64) -> f64 { x.sqrt() } fn sqrt2