Passing program arguments through Cargo

You can pass trailing arguments to cargo run using –: cargo run — –test From the man page: All of the trailing arguments are passed to the binary to run. If you’re passing arguments to both Cargo and the binary, the ones after — go to the binary, the ones before go to Cargo.

How do you disable dead code warnings at the crate level in Rust?

You can either: Add an allow attribute on a struct, module, function, etc.: #[allow(dead_code)] struct SemanticDirection; Add an allow as a crate-level attribute; notice the !: #![allow(dead_code)] Pass it to rustc: rustc -A dead_code main.rs Pass it using cargo via the RUSTFLAGS environment variable: RUSTFLAGS=”$RUSTFLAGS -A dead_code” cargo build

How do I print a vector of u8 as a string?

If you look at the String documentation, there are a few methods you could use. There’s String::from_utf8 that takes a Vec<u8>, and there’s also String::from_utf8_lossy which takes a &[u8]. Note that a Vec<T> is more-or-less an owned, resizable wrapper around a [T]. That is, if you have a Vec<u8>, you can turn it into a … Read more

Setting the include path with bindgen

With the API you can use Builder::clang_arg with arbitrary arguments: let b = bindgen::builder().header(“foo.h”).clang_arg(“-I/path”); From the command line you can do the same by appending arguments after –, like: bindgen foo.h — -I/path

How to pass RUST_BACKTRACE=1 when running a Rust binary installed in Debian?

Just in case someone is looking for setting environment variable from source code, here is how you do it: use std::env; fn main() { // this method needs to be inside main() method env::set_var(“RUST_BACKTRACE”, “1”); } The benefit of this approach — in contrast to manually setting the env variable from PowerShell– is that you … Read more

Why did Rust remove the green-threading model; what’s the disadvantage?

Erlang uses green threads with preemption. This is possible only because Erlang has a VM, which also allows a lot of other things like code hotswap. But languages with VM are unsuitable for systems programming because they always have some constant overhead, both in memory and processing power. Rust is a systems programming language, and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)