rust

Reason of the error expected (), found struct `std::vec::Vec` in Rust?

你说的曾经没有我的故事 提交于 2020-11-29 18:55:51
问题 I am new to rust programming. I wanted to implement merge sort with recursion. Here is my code: fn merge(a: &mut Vec<u32>, b: &mut Vec<u32>) -> Vec<u32> { let mut temp: Vec<u32> = Vec::new(); println!("The digit is {}", a[0]); while a.len() > 0 && b.len() > 0 { if a[0] > b[0] { temp.push(a[0]); a.pop(); } else { temp.push(b[0]); b.pop(); } } while a.len() > 0 { temp.push(a[0]); a.pop(); } while b.len() > 0 { temp.push(b[0]); b.pop(); } temp } fn merge_sort(v: &mut Vec<u32>) -> Vec<u32> {

Reason of the error expected (), found struct `std::vec::Vec` in Rust?

邮差的信 提交于 2020-11-29 18:55:42
问题 I am new to rust programming. I wanted to implement merge sort with recursion. Here is my code: fn merge(a: &mut Vec<u32>, b: &mut Vec<u32>) -> Vec<u32> { let mut temp: Vec<u32> = Vec::new(); println!("The digit is {}", a[0]); while a.len() > 0 && b.len() > 0 { if a[0] > b[0] { temp.push(a[0]); a.pop(); } else { temp.push(b[0]); b.pop(); } } while a.len() > 0 { temp.push(a[0]); a.pop(); } while b.len() > 0 { temp.push(b[0]); b.pop(); } temp } fn merge_sort(v: &mut Vec<u32>) -> Vec<u32> {

Do I need to move away from Tokio as I cannot split streams in TLS connections?

↘锁芯ラ 提交于 2020-11-29 11:11:03
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Do I need to move away from Tokio as I cannot split streams in TLS connections?

本小妞迷上赌 提交于 2020-11-29 11:10:58
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Do I need to move away from Tokio as I cannot split streams in TLS connections?

为君一笑 提交于 2020-11-29 11:10:39
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

How to use Serde to parse a field that might fail to be deserialized without failing the entire deserialization?

我与影子孤独终老i 提交于 2020-11-29 09:41:57
问题 I am deserializing some JSON objects which come in as requests. The input body is nested, but a certain field is sometimes misformatted for a variety of reasons. In that situation I still want the rest of the object. This doesn't all have to be done through serde; but what is happening now, is that if a single subfield is messed up, the whole request is trashed. I want to somehow still deserialize that result and just mark the field as errored out. How can this be done? E.g. the data schema

How to use Serde to parse a field that might fail to be deserialized without failing the entire deserialization?

百般思念 提交于 2020-11-29 09:40:05
问题 I am deserializing some JSON objects which come in as requests. The input body is nested, but a certain field is sometimes misformatted for a variety of reasons. In that situation I still want the rest of the object. This doesn't all have to be done through serde; but what is happening now, is that if a single subfield is messed up, the whole request is trashed. I want to somehow still deserialize that result and just mark the field as errored out. How can this be done? E.g. the data schema

How to set up CORS or OPTIONS for Rocket.rs

纵然是瞬间 提交于 2020-11-29 09:21:05
问题 I've got a backend running rocket.rs which my flutter web app sends a request to, but it can't get past the OPTIONS response. I have tried adding CORS (rocket_cors) to the backend and having a options response, but it still sends back: Error: XMLHttpRequest error. dart:sdk_internal 124039:30 get current packages/http/src/browser_client.dart.lib.js 214:124 <fn> I have added the following to my rocket project: #[options("/")] fn send_options<'a>(path: PathBuf) -> Response<'a> { let mut res =

What is the difference between library crates and normal crates in Rust?

怎甘沉沦 提交于 2020-11-29 09:05:50
问题 While reading the official book, I stumbled upon packages and crates. To create a new "project", this is what I ran: $ cargo new my-project Created binary (application) `my-project` package $ ls my-project Cargo.toml src $ ls my-project/src main.rs The book states the following: A package must contain zero or one library crates, and no more. It can contain as many binary crates as you’d like, but it must contain at least one crate (either library or binary). My doubt is, what is the

What is the difference between library crates and normal crates in Rust?

烈酒焚心 提交于 2020-11-29 09:01:27
问题 While reading the official book, I stumbled upon packages and crates. To create a new "project", this is what I ran: $ cargo new my-project Created binary (application) `my-project` package $ ls my-project Cargo.toml src $ ls my-project/src main.rs The book states the following: A package must contain zero or one library crates, and no more. It can contain as many binary crates as you’d like, but it must contain at least one crate (either library or binary). My doubt is, what is the