Posts Tagged - rust

From Java to Rust

Relevant Post: Initial Steps with Rust

Relevant changes to adapt to Rust, coming from a Java background. Contains information about Rust’s environment and the language structures.

For code snippets on how to do specific things as we do in Java, check my Rust experience post

Rust Environment

Cargo

Cargo is Rust’s dependencies manager and most projects should be created and managed with it, for easier use.
Commands I used so far:

cargo new hello_cargo creates a new project.
Cargo.toml is a file which cargo creates and it contains the project’s metainformation and its dependencies.

cargo build builds binaries from source code.
cargo run directly compiles and starts the programm.

cargo install --path . installs from binaries to your system. Useful to use and test my own programs.
--force needed if it already was installed

Read More

Rust experience sheet

Relevant Post: From Java to Rust

Answers to questions I’ve spent some time looking on the Internet to find an answer to, or which come to be relevant often.

Compare between String and &str

If we’re comparing 2 Strings and Rust shows the error expected 'String', found '&str' is because we forgot to add the .trim() part to buffer.

let mut buffer = String::new();
io::stdin().lock()
  .read_line(&mut buffer)
  .expect("Couldn't read user input");

if buffer.trim() == "yes" {
  // do action
}  

Read More