Linking Rust application with a dynamic library not in the runtime linker search path

Here’s a Minimal, Reproducible Example that exhibits the same problem that you experienced. I created a C library exporting a simple addition function. I also created a Cargo project to use this function. dynlink/ ├── executable │   ├── build.rs │   ├── Cargo.lock │   ├── Cargo.toml │   └── src │      └── main.rs └── library ├── … Read more

How can I convert a hex string to a u8 slice?

You can also implement hex encoding and decoding yourself, in case you want to avoid the dependency on the hex crate: use std::{fmt::Write, num::ParseIntError}; pub fn decode_hex(s: &str) -> Result<Vec<u8>, ParseIntError> { (0..s.len()) .step_by(2) .map(|i| u8::from_str_radix(&s[i..i + 2], 16)) .collect() } pub fn encode_hex(bytes: &[u8]) -> String { let mut s = String::with_capacity(bytes.len() * 2); … Read more

Include git commit hash as string into Rust program

Since Rust 1.19 (cargo 0.20.0), thanks to https://github.com/rust-lang/cargo/pull/3929, you can now define a compile-time environment variable (env!(…)) for rustc and rustdoc via: println!(“cargo:rustc-env=KEY=value”); So OP’s program can be written as: // build.rs use std::process::Command; fn main() { // note: add error checking yourself. let output = Command::new(“git”).args(&[“rev-parse”, “HEAD”]).output().unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); println!(“cargo:rustc-env=GIT_HASH={}”, git_hash); } … Read more

How do I sort a map by order of insertion?

None of the standard library collections maintain insertion order. You can instead use IndexMap from the indexmap crate, which preserves insertion order as long as you don’t call remove. use indexmap::indexmap; let map = indexmap! { “Z” => 1, “T” => 2, “R” => 3, “P” => 4, “K” => 5, “W” => 6, }; … Read more

cannot return reference to temporary value

Anything starting with & in Rust is a reference to a value, rather than a value itself. A &[u8] is a reference to a value which needs to exist elsewhere. Because you create the value it’s a reference to within the function, when the function returns, the value the reference points to no longer exists. … Read more

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