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.
51 questions
4
votes
3
answers
314
views
The applicability of functional core - imperative shell to a cli program which contains a wrapper around a binary
Not long ago while I was exploring for solutions to test without mocks I've found out about the functional core, imperative shell architecture. It sounds great, I also think that it would play nicely ...
2
votes
3
answers
317
views
Aggregate with a huge list of value objects
I'm currently reading "Implementing Domain-Driven Design" while going through the code samples, but I'm having trouble modeling aggregates that stores a huge list of value objects. For ...
0
votes
2
answers
343
views
Intuition behind why Rust's io::stdin().read_line() relies on a side effect?
I'm reading the second chapter of the official Rust book as a pretty seasoned python programmer. As you can imagine, its been pretty jarring, but I'm learning.
My specific question is about whether or ...
1
vote
1
answer
240
views
How difficult would it be to extend Rust's compile time checking to dynamic linking?
When compiling Rust, various additional checks are made for correctness. These include bounds checking, borrow checking for multithreading and memory ownership, and the like. Once compiled, these ...
0
votes
2
answers
107
views
Deserializing serial protocol enums: Recoverable or unrecoverable errors?
I am currently implementing a library in Rust that implements a proprietary serial protocol.
The protocol specifies several enum values, that mostly are returned by the hardware as u8s (bytes), but ...
1
vote
0
answers
165
views
How can I represent a transformed AST between compilation stages?
I'm writing a compiler in Rust. I've reached the point where I have an AST and am ready to do symbol resolution, type-checking, etc. But, I'm unsure of how to represent an AST as containing "...
1
vote
0
answers
148
views
Designing an API adapter with multiple authentication types
I'm building an HTTP API database adapter that has an authentication component. Users can authenticate using password, federated login such as OAUTH, and JWT.
My initial design is something like the ...
2
votes
1
answer
672
views
Representing Rust enums in databases
Although I love Rust's enums (and the idea of making illegal states unrepresentable), I'm struggling to represent (ironic, yes) them in databases like PostgreSQL when the variants have data associated ...
2
votes
1
answer
2k
views
Build a Rust project using Clean architecture and DB transactions in the same DDD bounded context
This is just an example of an (still incomplete) real-world project written in Rust using a clean architecture: https://github.com/frederikhors/rust-clean-architecture-with-db-transactions.
Goals
My ...
1
vote
1
answer
362
views
Creating a new type as slice of strings in Rust?
I have a little bit of experience with Go, that I have been trying to use as a reference point to wrap my mind around Rust via a cards game I wrote in Go that I would like to now write in Rust.
I know ...
-2
votes
1
answer
166
views
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)
...
4
votes
5
answers
2k
views
(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 ...
4
votes
1
answer
565
views
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::...
67
votes
9
answers
9k
views
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 = ...
3
votes
1
answer
3k
views
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 ...
10
votes
1
answer
452
views
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 ...
5
votes
3
answers
541
views
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 ...
10
votes
5
answers
846
views
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 ...
4
votes
1
answer
657
views
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++?
-2
votes
1
answer
359
views
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 {}", ...
8
votes
2
answers
753
views
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,...
6
votes
1
answer
462
views
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 "...
40
votes
2
answers
4k
views
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.
...
7
votes
1
answer
564
views
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 ...
11
votes
2
answers
4k
views
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 ...