Posts

Showing posts with the label Rust

Cross-compile A Rust Application From Linux To Windows

Answer : Other answers, while technically correct, are more difficult than they need to be. There's no need to use rustc (in fact it's discouraged, just use cargo ), you only need rustup , cargo and your distribution's mingw-w64. Add the target (you can also change this for whatever target you're cross compiling for): rustup target add x86_64-pc-windows-gnu rustup toolchain install stable-x86_64-pc-windows-gnu You can build your crate easily with: cargo build --target x86_64-pc-windows-gnu No need for messing around with ~/.cargo/config or anything else. EDIT: Just wanted to add that while you can use the above it can also sometimes be a headache. I wanted to add that the rust tools team also maintains a project called cross: https://github.com/rust-embedded/cross This might be another solution that you want to look into The Rust distribution only provides compiled libraries for the host system. However, according to Arch Linux's wiki page on Rust, you could c...

Build HashSet From A Vector In Rust

Answer : Because the operation does not need to consume the vector¹, I think it should not consume it. That only leads to extra copying somewhere else in the program: use std::collections::HashSet; use std::iter::FromIterator; fn hashset(data: &[u8]) -> HashSet<u8> { HashSet::from_iter(data.iter().cloned()) } Call it like hashset(&v) where v is a Vec<u8> or other thing that coerces to a slice. There are of course more ways to write this, to be generic and all that, but this answer sticks to just introducing the thing I wanted to focus on. ¹This is based on that the element type u8 is Copy , i.e. it does not have ownership semantics. The following should work nicely; it fulfills your requirements: use std::collections::HashSet; use std::iter::FromIterator; fn vec_to_set(vec: Vec<u8>) -> HashSet<u8> { HashSet::from_iter(vec) } from_iter() works on types implementing IntoIterator , so a Vec argument is sufficient. Ad...