rust

Issue passing mutable Arc reference to hyper service_fn handler

蹲街弑〆低调 提交于 2021-01-24 07:09:21
问题 I've been trying the following Relevant imports and code shown use std::sync::{Arc, Mutex}; use std::thread; use hyper::rt::{self, Future, Stream}; use hyper::service::service_fn; use hyper::{Body, Request, Response, Server, StatusCode}; pub struct ChallengeState; pub struct ChallengeResponse; type BoxFut<'a> = Box<Future<Item = Response<Body>, Error = hyper::Error> + Send + 'a>; fn handle_challengeproof<'a>( req: Request<Body>, challenge: &Arc<Mutex<ChallengeState>>, ) -> BoxFut<'a> { let

Rust vs python program performance results question

ぃ、小莉子 提交于 2021-01-23 07:50:46
问题 I wrote a program that count words. Here is the program use std::collections::HashMap; use std::io; use std::io::prelude::*; #[derive(Debug)] struct Entry { word: String, count: u32, } static SEPARATORS: &'static [char] = &[ ' ', ',', '.', '!', '?', '\'', '"', '\n', '(', ')', '#', '{', '}', '[', ']', '-', ';', ':', ]; fn main() { if let Err(err) = try_main() { if err.kind() == std::io::ErrorKind::BrokenPipe { return; } // Ignore any error that may occur while writing to stderr. let _ =

Rust vs python program performance results question

≡放荡痞女 提交于 2021-01-23 07:49:31
问题 I wrote a program that count words. Here is the program use std::collections::HashMap; use std::io; use std::io::prelude::*; #[derive(Debug)] struct Entry { word: String, count: u32, } static SEPARATORS: &'static [char] = &[ ' ', ',', '.', '!', '?', '\'', '"', '\n', '(', ')', '#', '{', '}', '[', ']', '-', ';', ':', ]; fn main() { if let Err(err) = try_main() { if err.kind() == std::io::ErrorKind::BrokenPipe { return; } // Ignore any error that may occur while writing to stderr. let _ =

How to run an asynchronous task from a non-main thread in Tokio?

随声附和 提交于 2021-01-22 03:56:24
问题 use std::thread; use tokio::task; // 0.3.4 #[tokio::main] async fn main() { thread::spawn(|| { task::spawn(async { println!("123"); }); }) .join(); } When compiling I get a warning: 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

How to run an asynchronous task from a non-main thread in Tokio?

你。 提交于 2021-01-22 03:53:29
问题 use std::thread; use tokio::task; // 0.3.4 #[tokio::main] async fn main() { thread::spawn(|| { task::spawn(async { println!("123"); }); }) .join(); } When compiling I get a warning: 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

How to run an asynchronous task from a non-main thread in Tokio?

我只是一个虾纸丫 提交于 2021-01-22 03:52:42
问题 use std::thread; use tokio::task; // 0.3.4 #[tokio::main] async fn main() { thread::spawn(|| { task::spawn(async { println!("123"); }); }) .join(); } When compiling I get a warning: 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

How to properly implement Iterable structure in Rust? [duplicate]

╄→гoц情女王★ 提交于 2021-01-21 08:11:28
问题 This question already has answers here : How to implement Iterator and IntoIterator for a simple struct? (2 answers) Closed 1 year ago . I'm trying to implement a structure that can be infinitely iterated. Think it like a natural number. I have a limitation: it can't implement Copy trait because the structure contains a String field. I've also implemented an Iterable trait and its only member fn next(&mut self) -> Option<Self::Item> . Currently, I have the following code to iterate over the

How to compile a static musl binary of a Rust project with native dependencies?

我是研究僧i 提交于 2021-01-21 07:43:28
问题 I have a project with dependencies on Hyper and Diesel, and because of that, on native libraries OpenSSL and libpq. The project builds on nightly Rust because it uses compiler plugins. My current attempt is to build on a Docker container. I have the MUSL libc and the libraries make 'd and installed with prefix /usr/local/musl . I run cargo with the following command: (Not sure if some of the options are redundant, I'm not too well-versed with the compiler chain, and not even sure if they end

Use all but the last element from an iterator

浪子不回头ぞ 提交于 2021-01-21 07:12:09
问题 I want to split a Vec into some parts of equal length, and then map over them. I have an iterator resulting from a call to Vec 's chunks() method. This may leave me with a part that will be smaller than other parts, which will be the last element generated by it. To be sure that all parts have equal length, I just want to drop that last element and then call map() on what's left. 回答1: As Sebastian Redl points out, checking the len gth of each chunk is the better solution for your specific

Use all but the last element from an iterator

对着背影说爱祢 提交于 2021-01-21 07:11:15
问题 I want to split a Vec into some parts of equal length, and then map over them. I have an iterator resulting from a call to Vec 's chunks() method. This may leave me with a part that will be smaller than other parts, which will be the last element generated by it. To be sure that all parts have equal length, I just want to drop that last element and then call map() on what's left. 回答1: As Sebastian Redl points out, checking the len gth of each chunk is the better solution for your specific