rust Questions
3
Solved
I am trying to start a process with the Command API and redirect its standard output to standard error. The following fails:
Command::new("tput")
.arg("rc")
.stdout(io::stderr...
Deduct asked 7/2, 2017 at 23:27
1
I'm trying to debug an EFI application in qemu with gdb. QEMU is started with -s and -S flags and gdb is started with
gdb ./target/x86_64-unknown-uefi/debug/application.efi
and qemu is targeted wi...
4
Solved
I want to iterate over over the fields of a struct and access its respective value for each iteration:
#[derive(Default, Debug)]
struct A {
foo: String,
bar: String,
baz: String
}
fn main() {
...
Dagmardagna asked 5/1, 2020 at 14:15
4
Solved
Consider the following example from the Book:
fn main() {
let string1 = String::from("abcd");
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
println!...
Discrepant asked 2/6, 2021 at 9:32
3
Solved
How do I add an input event listener to an HtmlInputElement/HtmlTextAreaElement?
I'm using web-sys and read this, but following that, all the elements I use inside the closure (in this case especia...
3
Solved
How do I generate a vector of 100 64-bit integer values in the range from 1 to 20, allowing duplicates?
2
Solved
I'm trying to export the following struct:
#[wasm_bindgen]
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum TokenType {
KeywordLiteral,
NumberLiteral,
Operator,
Separator,
StringLiteral,
}
#[w...
Rojo asked 4/7, 2021 at 10:48
3
Solved
How do I find out the dependencies in Cargo.toml that are unused? How can I remove them automatically?
Transpacific asked 2/5, 2022 at 5:12
3
Solved
I've tried this repeatedly and still can't figure out where I'm going wrong.
I installed Rust from the official website (version 1.44.1), and I can run rustc --version and get the right result. I c...
Haileyhailfellowwellmet asked 26/6, 2020 at 2:21
2
Trying to get the full request URI (scheme + authority + path)
I have found the discussion: https://github.com/tokio-rs/axum/discussions/1149 which says that Request.uri() should have it.
So I trie...
2
Solved
The solution from How do I store a variable of type `impl Trait` in a struct? suggests creating a Future trait object. Doing that in my real code generates an error that the type is not Send, but t...
2
Solved
I have a library crate which I want to profile using cargo flamegraph. But however I try to run cargo flamegraph, I get error messages. The library has the following structure:
utilrs
├── Cargo.loc...
Kaiserslautern asked 23/10, 2022 at 15:11
4
Solved
I would like to replicate the behavior and ergonomics of taking a closure/function as an argument much like map does: iterator.map(|x| ...).
I've noticed that some library code allows passing in a...
Oletta asked 17/3, 2020 at 7:12
1
Solved
I would like to implement an async function that takes async closure as the argument, so it must be called this way somewhere in the code:
my_func(async || { ... }).await;
What is the correct way ...
Timisoara asked 23/7 at 13:8
6
Solved
I join these two questions in one, as they maybe are related. A few days ago, I started having this error in the [#actix_rt::main] line, before the main function:
proc macro `main` not expanded: ca...
Monoatomic asked 4/5, 2023 at 9:2
2
Solved
I'm trying to build a vector of points that are changed while iterating over them:
struct Point {
x: i16,
y: i16,
}
fn main() {
let mut points: Vec<Point> = vec![];
// unsure if point i...
Emersen asked 28/3, 2015 at 21:38
2
Solved
I can set a breakpoint manualy, and run with debugger, but I can't set a breakpoint at a panic of a Rust program. How can I set a breakpoint at a panic like I would an exception in C++?
I'm using ...
Enculturation asked 1/8, 2018 at 16:39
2
Solved
The third rule of lifetime elision says
If there are multiple input lifetime parameters, but one of them is &self or &mut self because this is a method, then the lifetime of self is assi...
9
From what I see in the documentation, there is no out-of-the-box solution.
Valenba asked 16/11, 2014 at 15:16
3
Solved
This works because Iterator implements rev() where self is a DoubleEndedIterator:
let vec: Vec<i32> = Vec::new();
for x in vec.iter().rev() {
//Do stuff
}
However, if I change vec.iter()....
3
Solved
I'm developing code for the Codingame problems using VS Code on Windows with Rust and the Visual Studio toolchain.
I have found multiple guides explaining how to debug the executable generated by ...
Hoffmann asked 5/6, 2018 at 18:54
2
Solved
The following code (playground) fails to compile:
async fn wrapper<F, Fut>(func: F)
where
F: FnOnce(&i32) -> Fut,
Fut: Future<Output = ()>,
{
let i = 5;
func(&i).await;
}...
Angularity asked 12/10, 2020 at 15:17
3
Solved
I need to instrument spans with different names dynamically. How can I create a tracing span with dynamic naming?
use tracing; // 0.1.22
fn main() {
let name: &'static str = "foo bar&quo...
Handout asked 15/1, 2021 at 11:52
2
I tried to run a simple Rust test in IntelliJ.
The test command IntelliJ uses is:
cargo test --color=always --package myproject-rust --lib mycode::tests --no-fail-fast -- --format=json -Z unstable-...
Extraditable asked 19/8, 2023 at 18:49
2
Solved
I noticed the rust book recommends to use Rc::clone(&rc) over rc.clone() as follows:
use std::rc::Rc;
let five = Rc::new(5);
// recommended
let _ = Rc::clone(&five);
// not recommended
l...
Cupola asked 22/5, 2020 at 7:23
© 2022 - 2024 — McMap. All rights reserved.