43,911 questions
Advice
1
vote
5
replies
62
views
"if let" assignment with specified data-type
It's good practice for readable code to specify the actual data type in let assignments, if the right side is complex or misleading. Like:
let strange: DataType::<ComplexWorld<f32>> = ...
2
votes
2
answers
44
views
How to do equality check on subset of Rust struct without excessive boilerplate code
Does anyone know how to make it work ( without clone() , without excessive boilerplate code, without repeating .a or .b ( imagine having many such sub-fields in real life code, with large field names,...
2
votes
1
answer
56
views
calling type_id() on a &mut variable
I have this snippet that gives me a compile error:
fn main() {
let mut t = String::from("Hello, world!");
let tt = &mut t;
tt.type_id();
}
error:
error[E0597]: `t` does not ...
0
votes
0
answers
25
views
Regarding the menu theme created with Tauri v2
Even if I run setTheme("light") in my browser and view the Tauri menu,
it remains in the dark theme. The system theme is dark.
Is there a way to change the menu theme?
import { setTheme } ...
0
votes
1
answer
44
views
Question about reference of permission Read and Own
From references-change-permissions-on-places, places have three kinds of permission on their data:
Read (R): data can be copied to another location.
Write (W): data can be mutated.
Own (O): data ...
0
votes
0
answers
30
views
Implementation of the (modular) visitor design pattern
I am creating a QueryBuilder, so I though that it w'd be amazing to serialize objects to tokens, and have an AST within the QueryBuilder. So I immediatly though about the Visitor Design Pattern.
Here'...
0
votes
1
answer
48
views
Rust Iced Markdown View isn't Showing in the window
I've tried the rust iced framework and tried to create a markdown view from the documentation and the code compiles and renderes the windows but the code
pub fn new() -> Self {
Self {
...
0
votes
1
answer
73
views
What happens when I take in &str with AsRef<Path>?
I have the following implementation of to_file for a struct which takes a parameter with AsRef<Path>:
pub fn to_file(&self, path: impl AsRef<Path>) -> anyhow::Result<()> {
...
1
vote
0
answers
64
views
How would I create a shared memory buffer to display animations using the Kitty Graphics Protocol in Rust?
I'm using Arch Linux with Wayland. My terminal is Kitty.
I'm trying to create an animation using the Kitty Graphics Protocol. However, I want this animation to cover the whole screen and run at 60 fps....
Best practices
0
votes
2
replies
68
views
Can I have a reference to a variable while still allowing that variable to be mutated in Rust?
Is there a way that I can have a reference to a variable while allowing that variable to be mutated in Rust, so long as I "pinky promise not to access the data of the stored variable" so ...
Best practices
0
votes
4
replies
49
views
In rust, is there an iterator adapter that can consume multiple (but not all) items before producing an output?
I can't help thinking this is not an uncommon idiom and I'm just being an idiot but I've spent ages searching SO and reading the docs for std::iter and for the itertools crate and have got nowhere. ...
-2
votes
1
answer
78
views
Why BufReader.read_line(&mut buf) reads all file content into buf? [duplicate]
I'm new learning rust and this is an issue with BufReader.read_line().
In the official documentation it says "This function will read bytes from the underlying stream until the newline delimiter (...
0
votes
0
answers
56
views
How to use std::vec::windows to look for a sequence with repeated elements removed
I have a list of elements in an array in which I'm looking for a sequence. Using std::vec::windows::any, I was able to confirm presence/absence of a given sequence. I'm facing an issue if there are ...
0
votes
0
answers
42
views
Why does `-fuse-ld=lld` when targeting `aarch64-unknown-linux-musl` cause the binary to dynamically-link the interpreter?
I've got a working Rust cross-compile setup on Arch Linux, targeting x86_64-unknown-linux-musl and aarch64-unknown-linux-musl from a x86_64 host.
By default, binaries for both targets are fully ...
6
votes
1
answer
205
views
Shared assembly between Rust and C using preprocessor
I am using Rust to target a baremetal system.
My startup code is written in Assembly and is in crt0.S, it is shared between Rust, C and Assembly projects.
crt0.S contains:
#include "constants.h&...