Skip to main content

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
1 vote
1 answer
143 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 ...
John Moser's user avatar
0 votes
2 answers
457 views

What problem does Rust's "atomic reference count" actually solve?

The Rust programming language offers a Arc atomic reference counting generic type for use in multi-threading environment, since Rc is optimized for performance in single-threaded applications, and ...
DannyNiu's user avatar
  • 219
0 votes
2 answers
83 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 ...
Richard Neumann's user avatar
0 votes
0 answers
17 views

Feedback on API design of a HalfEdge Data structure

Background Sometimes also referred to as doubly connected edge list, the HalfEdge data structure allows programmers to efficiently and easily modify topological and geometric properties of a mesh. ...
Makogan's user avatar
  • 261
0 votes
0 answers
53 views

Single-threaded request-response type server architecture

I'm writing an internet service in Rust that works more or less like an HTTP-server, just without the HTTP part, and strictly over UDP. I also have a requirement to build it like an old-school game of ...
laggyfrog's user avatar
0 votes
3 answers
153 views

Is there a distinct optional type semantically representing a value that *needs to be calculated later*?

Semantically, C++ std::optional, Rust Option<T>, and other optional/nullable types represent a value that can be present or absent: you have to handle both cases, or you can opt-in to crash. Is ...
JJW's user avatar
  • 9
1 vote
0 answers
99 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 "...
gmdev's user avatar
  • 119
0 votes
2 answers
93 views

What are the pros and cons of structuring an application as a pipeline of functions mutating a shared struct?

I could not find anything regarding this question except some lecture notes about game design and a book which describes something similar but not quite the same. General Description The approach is ...
laggyfrog's user avatar
1 vote
0 answers
85 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 ...
seve's user avatar
  • 19
21 votes
5 answers
15k views

How can Rust be "safer" and "faster" than C++ at the same time?

I have been told that Rust is both safer and faster than C++. If that is true, how can that be even possible? I mean, a safer language means that more code is written inside the compiler, right? More ...
euraad's user avatar
  • 335
1 vote
1 answer
399 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 ...
yoshke's user avatar
  • 19
-2 votes
1 answer
76 views

How would data be dynamically queried in rust

Say there is an user that wants to query a random element during runtime from a dynamic struct. The type of the data is unknown, but all the data is either a integer (size unknown), float, string, or ...
Star's user avatar
  • 1
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 ...
Fred Hors's user avatar
  • 139
-3 votes
1 answer
197 views

Will anything that's written in c/c++ be rerwritten in rust? [closed]

Will anything that's written in c/c++ be rerwritten in rust? for maintainance, even for performance?
Snowmanzzz's user avatar
0 votes
1 answer
69 views

Handling IO operations through a server and building the UI using a separate framework/application

I am trying to build a file editor, and I wanted to build the UI using Flutter. However I wanted to implement IO operations (reading a file, applying changes, etc) in Rust. The reason I would like to ...
Fabrizio's user avatar
  • 115
1 vote
1 answer
303 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 ...
Daniel's user avatar
  • 119
5 votes
1 answer
455 views

Why does Rust allow a leading `|` in or patterns?

In the code snippet found in this tweet, pattern matching is used like this: let (|x| x) = |_| Some(1); // same as `let (x | x) = |_| Some(1);` Which threw me off. Rust's pattern syntax is defined as:...
Calo's user avatar
  • 63
-2 votes
1 answer
136 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) ...
Roy King's user avatar
1 vote
2 answers
329 views

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 ...
Lionel's user avatar
  • 19
3 votes
5 answers
1k 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 ...
drkvogel's user avatar
  • 147
1 vote
1 answer
3k views

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 (...
Brian Reading's user avatar
4 votes
1 answer
470 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::...
Zomagk's user avatar
  • 261
2 votes
1 answer
142 views

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 ...
cpage's user avatar
  • 57
67 votes
9 answers
8k 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 = ...
Heinzi's user avatar
  • 9,798
2 votes
1 answer
409 views

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 ;). ...
jthulhu's user avatar
  • 141
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 ...
Truffle's user avatar
  • 39
3 votes
1 answer
3k views

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. ...
temarsden's user avatar
  • 139
9 votes
1 answer
420 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 ...
lovasoa's user avatar
  • 199
3 votes
2 answers
3k views

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. ...
Avinash's user avatar
  • 141
5 votes
3 answers
515 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 ...
Amin Sameti's user avatar
1 vote
1 answer
218 views

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 ...
Anders's user avatar
  • 1,361
10 votes
5 answers
794 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 ...
TheEnvironmentalist's user avatar
7 votes
0 answers
393 views

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 ...
user avatar
4 votes
1 answer
633 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++?
Greg's user avatar
  • 153
2 votes
1 answer
119 views

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 ...
tl8's user avatar
  • 131
-2 votes
1 answer
342 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 {}", ...
Tristan's user avatar
  • 21
4 votes
1 answer
682 views

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 ...
Jonny Dee's user avatar
  • 957
8 votes
2 answers
690 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,...
sadiq.ali's user avatar
  • 217
5 votes
1 answer
2k views

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?
Frederick Zhang's user avatar
6 votes
1 answer
347 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 "...
Jon Flow's user avatar
  • 373
19 votes
1 answer
2k views

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

Looking through this article on Rust's concurrency safety: http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html I was wondering how many of these ideas can be achieved in C++11 (or newer)....
Brannon's user avatar
  • 371
39 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. ...
thb's user avatar
  • 747
28 votes
8 answers
6k views

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 ...
Saurabh Nanda's user avatar
6 votes
1 answer
537 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 ...
vadix's user avatar
  • 71
4 votes
1 answer
4k views

Publishing a crate containing both lib.rs and main.rs files

In the Importing External Crates section of the Rust book the author creates main.rs file in an already existing library project. I randomly picked up a bunch of crates from crates.io, examined their ...
Sergey's user avatar
  • 263
9 votes
2 answers
3k 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 ...
stijn's user avatar
  • 4,138
0 votes
2 answers
124 views

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 }
tyro1's user avatar
  • 23
88 votes
1 answer
23k views

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 http://yager.io/programming/go....
Logan's user avatar
  • 983