Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 7245

Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without needing a garbage collector, making it a useful language for a number of use cases other languages aren't good at: embedding in other languages, programs with specific space and time requirements, and writing low-level code, like device drivers and operating systems.

4 votes
Accepted

single byte xor decryption code

extern crate hex; extern crate is generally not necessary for programs since the 2018 (currently latest) edition of Rust. … Of course, for a well-made command line program, you'd want to print your own better-formatted error message, instead of a Rust "panic" error. …
Kevin Reid's user avatar
2 votes
Accepted

Idiomatic Approach to Filter Struct Field - Rust

There is a method that directly does what you want: Vec::retain. pub fn remove_name(&mut self, name: &str){ self.current.names.retain(|n| n != name); } If retain didn't exist, it woul …
Kevin Reid's user avatar
8 votes
Accepted

Rust Simple Stats Program

io::stdin().read_line(&mut num); Here you are ignoring the Result from read_line; you should have seen a compiler warning about this. Add .unwrap() or .expect() to check the error and panic if there …
Kevin Reid's user avatar
5 votes
Accepted

Rust returning multiple errors

If you expect to handle the errors (to recover from them in a way that is specific to which error occurred), or if you're writing a library, then define an enum type which can hold any of the errors …
Kevin Reid's user avatar
2 votes

Rust: lazy_static the strings from evdev codes

short_key_name is a &str that was borrowed from key_name, a String allocated inside the loop and which will be dropped at the end of each loop iteration. Thus, it is not a &'static str. You can use Bo …
Kevin Reid's user avatar
1 vote
Accepted

Trying to find an idiomatic Rust way of calling a series of functions and early out'ing on f...

Technically you could use iterators to do this: pub fn new(data: &[u8]) -> Option<MyStruct> { let result = MyStruct { // initialize fields }; [ Sel …
Kevin Reid's user avatar
5 votes
Accepted

Make a config, that is periodically refreshed by a background thread, easily accessible to t...

You can change config: Arc<RwLock<Config>> ... fn get_config(&self) -> Config { to config: Arc<RwLock<Arc<Config>>>, ... fn get_config(&self) -> Arc<Config> { This way, while you do still need t …
Kevin Reid's user avatar
6 votes
Accepted

Handling default std::io::Error in Rust

Rust functions should be named with snake_case, not camelCase. Use standard code formatting, as performed by cargo fmt. …
Kevin Reid's user avatar
1 vote

First Rust program - squares which are sum of squares

The main readability improvement I see is using for and ranges for all of your loops — this is debatable but I see it as highlighting that the overall structure of your program is about iterating over …
Kevin Reid's user avatar
5 votes
Accepted

Custom derive macro to create getters and setters

The code uses both proc_macro and proc_macro2, is this necessary? This is normal. proc_macro is the compiler API stub, only available to proc-macro crates, and proc_macro2 is a plain library that do …
Kevin Reid's user avatar
3 votes
Accepted

Image scraper using Dependecy Injection in Rust with generics

is that how DI is supposed to be done in Rust? … The Rust toolchain includes a linter that will tell you things like this: run cargo clippy and see what it says. …
Kevin Reid's user avatar