Questions tagged [rust]

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.

Filter by
Sorted by
Tagged with
-2 votes
1 answer

What is a right way to handle requests?

A social network has API, but also it has some limitations like the amount of requests that can be done in one second (let's say API will give an error, if it accepts more than 3 requests per second) ...
1 vote
2 answers

Is it a good practice to allocate memory size to data types?

I'm learning rust and curious to know the purpose that we can allocate memory sizes to data types. I'm not clear yet how this could be an advantage. It can definitely save up some memory space but I ...
  • 19
3 votes
4 answers

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

I was reading about composition over inheritance and came across a question about solving the Circle-Ellipse Problem in Object-Oriented Programming. This kind of problem is often used as an example of ...
  • 147
1 vote
1 answer

What is the idiomatic way to split code between separate files in Rust?

Coming from the world of C#, where, despite sharing namespaces, it's quite common for every class to have its own file, I find that Rust codebases seem to have a complete different sort of philosophy (...
4 votes
1 answer

Is there a way to make Rust code more succinct?

Let's take at random a well-written piece of Rust code: let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), flags: wgpu::ShaderFlags::...
  • 261
2 votes
1 answer

Rust design when object needs to query outside data for some uses

I am modeling a ship that has contracts. Each contract can either be a fixed rate contract which pays a set fixed amount every day or a market index contract which pays an amount that varies based on ...
  • 57
60 votes
9 answers

Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?

Java has "checked exceptions", which force the caller of the method to either handle an exception or to rethrow it, e.g. // requires ParseException to be handled or rethrown int i = ...
  • 9,466
2 votes
1 answer

Rust/specs – what is the good/idiomatic way of design level walls/static objects handling in an ECS architecture

Warning: long question ahead, don't be afraid, I just tried to be as precise as possible about details for who wants them but many paragraphs are skipables if you already understood what I want ;). ...
3 votes
1 answer

Is this enum/trait a good way to implement polymorphic design in Rust?

this is my first post on here, and I'm wondering about a good rust implementation with traits on enum types. I want to know if using an enum w/ a trait as a generator of different code is viable like ...
  • 39
3 votes
1 answer

Managing const strings in a Rust project

I'm looking for a way to manage constant strings in a Rust project. The hope is to manage my strings from a single file and avoid having the same string literals all over the place in the project. ...
  • 139
9 votes
1 answer

How to design a good generic tiled image downloader?

Tiled images Tiled images are large images that have been split in smaller square tiles. There are several tiled image formats, with different ways of organizing the tile files. A tiled image on ...
  • 199
3 votes
2 answers

Can Rust replace the C or C++ programs in the Future? [closed]

I recently read an interesting Article that, due to a memory Overflow error Power system of Boeing will collapse and turns the Flight into a Flying Brick. This is a low level memory Handling bug. ...
  • 141
5 votes
3 answers

Why datatypes are marked as thread-safe instead of procedures?

In Rust, Send (or Sync) marker traits are used to indicate whether a value of a type (or a reference to that) can be worked on within threaded context. However, it is an attribute of a function or a ...
1 vote
1 answer

Signature for a Rust method that modifies object but might also drop it?

I'w writing a program in Rust that basically pushes data through a pipeline of steps that transforms it in different ways. The data is represented by an Entry, and I am designing a Step trait for the ...
  • 1,281
10 votes
5 answers

Is it possible to programmatically evaluate safety for arbitrary code?

I've been thinking a lot lately about safe code. Thread-safe. Memory-safe. Not-going-to-explode-in-your-face-with-a-segfault safe. But for the sake of clarity in the question, let's use Rust's safety ...
6 votes
0 answers

Rust and lifetime elision rules for structs?

In the Rust documentation, under the structs section, they give this example of how structs need lifetimes when they contain references: struct Foo<'a> { x: &'a i32, } because We ...
4 votes
1 answer

In what ways is Rust a "concurrent" language?

Rust is advertised as a "concurrent" language, what does this mean specifically and how is it different from other languages such as C++?
  • 153
2 votes
1 answer

Section of program needs root access

I have to perform a number of 'housekeeping' tasks that need root access (Linux, Debian). Generally one time only, but I do need to check that they have been performed. I don't really want to run the ...
  • 131
-3 votes
1 answer

Rust and composition [closed]

I have a piece of code. struct HasName { name: &'static str } trait CanGreet { fn greet(&self); } impl CanGreet for HasName { fn greet(&self) { println!("Hello {}", ...
  • 11
4 votes
1 answer

Can an object be moved through a match expression? [closed]

I am using Rust 1.15.1 and, recently, I stumbled over a problem I could not find a straight forward solution for. When you look at examples using pattern matching they usually destructure the object ...
  • 947
7 votes
1 answer

Comparision of modeling with inheritance vs idiomatic trait based composition

I recently I started learning Rust and Scala and what struck me was the lack of inheritance model that I'm used to in C++ and Java. Although I can model simple things with structs and traits in Rust,...
  • 207
5 votes
1 answer

Why does Rust require external linkers? Any other similar languages?

Rust needs external linkers (e.g. GCC) to generate final output. Why doesn't it provide a bundled one? Are there any languages that does the similar?
6 votes
1 answer

Implementing a construct like Rusts `match` in C?

I'm writing a compiler that compiles to C, one thing I'm attempting to do is implement a construct like Rust's match: // { some function let mut foo = 32; match foo { 3 => return "...
  • 353
19 votes
1 answer

Is it possible to achieve Rust's ownership model with a generic C++ wrapper?

Looking through this article on Rust's concurrency safety: I was wondering how many of these ideas can be achieved in C++11 (or newer)....
  • 361
39 votes
2 answers

How does Rust diverge from the concurrency facilities of C++?

Questions I am trying to understand whether Rust fundamentally and sufficiently improves upon the concurrency facilities of C++ so that to decide if I should spend the time to learn Rust. ...
  • 737
29 votes
8 answers

Using a "strong" type system in the real world, say, for large-scale web-apps?

I know this is a very broad, ambiguous, and possibly philosophical question. To an extent, that the most important keyword in the question - "strong" type system - itself, is ill-defined. So, let me ...
6 votes
1 answer

What is the most generic way to provide a variable amount of outputs from a Rust function?

I am currently writing an API for machine learning algorithms in Rust and I would like for a single genetic algorithm, artificial neural network, or Bayesian network to provide multiple outputs so ...
  • 71
4 votes
1 answer

Publishing a crate containing both and files

In the Importing External Crates section of the Rust book the author creates file in an already existing library project. I randomly picked up a bunch of crates from, examined their ...
  • 263
9 votes
2 answers

Rust-style error handling in C++

I've been reading some articles on how Rust does error handling using the Result<T, E> type and to me it seems like a hybrid best-of-both-worlds (exceptions and return codes) solution which can ...
  • 4,040
0 votes
2 answers

problems compiling a function with a trait Add in Rust [closed]

I'm trying to write a generic function summ in rust - but to no avail. Could someone please elucidate the problem? fn summ<T:Add>(a:T,b:T)->T { a+b }
  • 23
81 votes
1 answer

How are Rust Traits different from Go Interfaces?

I am relatively familiar with Go, having written a number of small programs in it. Rust, of course, I am less familiar with but keeping an eye on. Having recently read
  • 913