Make your voice heard. Take the 2019 Developer Survey now

Questions tagged [rust]

Rust is a language designed for writing highly reliable and fast software in a simple way. It can be used from high-level code down to hardware-specific code, and from big irons to tiny devices.

1
vote
0answers
18 views

Getting first member of a BTreeSet

In Rust, I have a BTreeSet that I'm using to keep my values in order. I have a loop that should retrieve and remove the first (lowest) member of the set. I'm using a cloned iterator to retrieve the ...
-2
votes
1answer
35 views

Drop can't be used in the generic struct implementing extended trait

TL;DR https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=99952dfdc8dab353992d2681de6b6f58 Full version https://play.rust-lang.org/?version=stable&mode=debug&...
0
votes
1answer
34 views

How to make a subscriber object with RAII properties?

I'm talking to some hardware over a link with kind of a publisher/subscriber model. In C++, I did subscriptions with RAII to remember to always unsubscribe, but I can't seem to get the ownerships/...
1
vote
1answer
36 views

How do I provide an implementation of a generic struct in Rust?

I have a struct MyStruct that takes a generic parameter T: SomeTrait, and I want to implement a new method for MyStruct. This works: /// Constraint for the type parameter `T` in MyStruct pub trait ...
1
vote
1answer
16 views

Why does calling tokio::spawn result in the panic “SpawnError { is_shutdown: true }”?

I want to use Delay to do some work later. If I use tokio::run, it just works fine, but it panics when using tokio::spawn: use std::sync::mpsc; use std::time::*; use tokio::prelude::*; // 0.1.14 fn ...
0
votes
0answers
25 views

Lifetime issue with the Any trait

I ran into a lifetime problem with a little game. The below code represents a very boiled down version of the update loop. I need the container mutable reference to get references to other game ...
0
votes
0answers
25 views

How do I turn on deny(unreachable_patterns) globally for my Rust program? [duplicate]

I want every function, in every file in my build to cause a compilation failure if a pattern is unreachable. How can I achieve this - by a compilation flag, etc?
1
vote
0answers
21 views

Append data to file and make sure it doesn't get corrupted

I have an existing file and I'd like to append data to it and make sure it can never (or almost never) get corrupted, even if something fails during writing of the appended data. One method for ...
0
votes
0answers
29 views

How do I return a reference to an Option of a custom struct inside of a lazy-static Arc Mutex? [duplicate]

I'm experimenting with Rust's Arc<Mutex>, trying to use it with a struct that is not in the default examples, but rather a custom one that is lazily initialized: use std::sync::{Arc, Mutex}; #[...
0
votes
0answers
23 views

Is there a way to get a mutable reference to an element of a vector and an immutable reference to the other elements? [duplicate]

I'm writing some simulation code with a vector of entities. Each entity must be updated with read access to the other entities. There are different types of entities, and each type can have one or ...
3
votes
1answer
58 views

Why does Rust use two bytes to represent this enum when only one is necessary?

It appears to be smart enough to only use one byte for A, but not smart enough to use one byte for B, even though there are only 8*8=64 possibilities. Is there any way to coax Rust to figure this out ...
2
votes
0answers
24 views

Making piston_window transparent

I am currently trying to use piston_window and just need to know how to make my piston_window transparent. I know that glutin_window supports with_transparency on it's window builder, but I don't know ...
1
vote
1answer
40 views

What is the intended way to match an interior mutable enum?

This Playground is the ways I could come up with, to try matching a reference counted, interior mutable enum. However most ways create an mismatched types error like error[E0308]: mismatched types -...
0
votes
1answer
51 views

How to use a reference to a FnOnce closure?

I have a function which needs to pass a closure argument recursively use std::cell::RefCell; use std::rc::Rc; pub struct TreeNode { val: i32, left: Option<Rc<RefCell<TreeNode>>...
0
votes
1answer
40 views

Filter Vector of Generic Structs

I'm trying to get this filter to work, my other tests pass but the find_by function isn't compiling. I'm getting an error no field name on type T. What am I missing here in regards to the filter ...

15 30 50 per page