rust Questions

5

Solved

In Python, this would be final_char = mystring[-1]. How can I do the same in Rust? I have tried mystring[mystring.len() - 1] but I get the error the type 'str' cannot be indexed by 'usize'
Hallux asked 6/2, 2018 at 11:46

3

Solved

sqlx has a query builder. Documentation can be seen here I see it supports dynamically buidling queries of the form: SELECT * FROM users WHERE (id, username) IN ((1, "test_user_1"), (2, &...
Catchfly asked 29/12, 2022 at 21:12

1

I'm running this in powershell for my Rust project: cargo build --target thumbv7em-none-eabihf And it produces this error after I try to execute this command: error: failed to parse manifest at C:\...
Shealy asked 30/3, 2022 at 0:31

3

Solved

Is this is the only possibility to get the content-type header from an Actix-Web request? This has to check if the header is available or if to_str failed... let req: actix_web::HttpRequest; let ...
Razorbill asked 21/10, 2018 at 20:17

1

Solved

I want to deserialize the following struct using serde_json. The parent_id field should accept an integer or a null, but I want it to return an error if the field is missing. #[derive(Debug, Serial...
Submultiple asked 9/7, 2024 at 9:51

3

Solved

I've just started playing with Rust and was trying to generate docs for the code I've written. When I issued cargo doc, I saw something a little weird. 21:53 $ cargo doc Compiling regex-syntax v0...
Casualty asked 11/12, 2015 at 2:59

1

tldr;> Given a trait function that takes a generic callback argument which returns an associated type, the compiler complains that the associated type may borrow arguments from the callback func...
Quadrangular asked 14/8, 2023 at 1:25

1

Solved

I am making a Maturin project involving Polars on both the Python and Rust side. In Python I have a dataframe with columns a and b: import polars as pl df = pl.DataFrame({'a': [1, 2], 'b': ['foo', ...
Teleran asked 7/3, 2024 at 8:9

6

Solved

I am new to Rust and working on the exercise in Chapter 12.3 in the book. I am pretty confident that my code is the same as that in the book (hard to tell for sure because of the 'snips'). However...
Subsistent asked 7/12, 2018 at 22:16

2

I have this code, for which borrow checker shows error: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=55d050b6f25410ce0e17ef9e844b048d fn f1(v: &str) { } ...
Titfer asked 12/9, 2020 at 1:31

2

Solved

I'm trying to write an x86 bootloader and operating system completely in Rust (no separate assembly files, only inline assembly within Rust). My bootloader works completely as intended within the Q...
Maurilla asked 5/7, 2024 at 0:31

3

Trying to compile the following Rust code mod traits { pub trait Dog { fn bark(&self) { println!("Bow"); } } } struct Dog; impl traits::Dog for Dog {} fn main() { let dog = Dog; dog....
Cookery asked 6/6, 2015 at 17:18

6

Solved

I'm using Rust 1.35.0 to try out some Rust examples and I could not get it to compile, as I keep getting the following message: error[E0463]: can't find crate for `core` I ran rustc --explain E0...
Hanan asked 31/5, 2019 at 6:2

4

Solved

I want to conditionally compile my source code using cfg with Cargo, after Googling for a while, it seems that the solution is to use cargo --features. http://doc.crates.io/manifest.html I tried ...
Leticialetisha asked 24/12, 2014 at 6:40

2

Solved

The Rust tutorial example of a linked list is: enum List { Cons(u32, Box<List>), Nil } What exactly is the Cons() struct? (It is a struct right?) I can't find any documentation on this a...
Calais asked 26/4, 2014 at 13:45

1

I have program that has a large lookup table in it. To save time, rather than generating the appropriate values every time the program runs, I simply load it from a file. When I read the values f...
Cesta asked 7/1, 2017 at 23:8

1

I think I understood how lifetimes work with function parameters/outputs and with structs, since those cases are explained in the book (and further in the nomicon), but I do not understand how life...
Evangelize asked 13/5, 2020 at 19:50

1

Solved

Let's say you have an enum: enum Expr { binExp, unExp, Literal, Group, } Should you prefer match or if/else chains to call methods based on Expr? match self { Expr::binExp => todo!(), ...
Madalynmadam asked 9/4, 2022 at 9:37

3

Solved

Is there a idiomatic Rust way to get the number of days in a given month? I've looked at chrono but I haven't found anything in the docs for this. I'm looking for something that can manage leap ye...
Endocarditis asked 8/12, 2018 at 21:13

9

I am using a Python virtual environment to work on a project. After setting up my venv and pulling from git I tried to pip install -r requirements.txt but am getting the following error: Collecting...
Ish asked 31/3, 2022 at 17:5

16

Solved

I'm facing the error failed to run custom build command for openssl-sys v0.9.60 while trying to build my rust program. Here are the main.rs and the Cargo.toml files. main.rs extern crate reqwest; ...
Bernardinebernardo asked 3/1, 2021 at 18:41

2

Solved

I'm writing a program in Rust that creates a file at a user-defined path. I need to be able to normalize intermediate components (~/ should become $HOME/, ../ should go up a directory, etc.) in ord...
Aggregation asked 2/7, 2021 at 21:14

6

Solved

Assumption -- The Vec<f32> does not have any NaN values or exhibit any NaN behavior. Take the following sample set: 0.28 0.3102 0.9856 0.3679 0.3697 0.46 0.4311 0.9781 0.9891 0.5052 0.917...
Donley asked 23/12, 2018 at 11:42

3

Solved

I am using MacOS Big Sur, and i am trying to cross compile to windows, but the problem is, this "error: linker x86_64-w64-mingw32-gcc not found" prevents me from doing that, here are my c...
Zubkoff asked 25/3, 2022 at 21:18

2

Solved

I'm trying to port this program that computes the nth derivative of x^x symbolically to Rust. It seems to be mostly easy: use std::rc::Rc; type Expr = Rc<Expr2>; enum Expr2 { Int(i32), V...
Phasia asked 14/1, 2018 at 3:43

© 2022 - 2025 — McMap. All rights reserved.