Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Last active September 4, 2023 20:17
Show Gist options
  • Save pcgeek86/13df1702848bfbd82b47af35afc67efb to your computer and use it in GitHub Desktop.
Save pcgeek86/13df1702848bfbd82b47af35afc67efb to your computer and use it in GitHub Desktop.
Rust Cheatsheet Examples 🦀
// This example shows how to prompt a user for input
// and convert the results to a Rust String type.
fn main() {
let buffer = &mut String::from("");
std::io::stdin().read_line(buffer).unwrap();
let input = buffer.replace("\n", "");
println!("{}no-new-line", input);
}
// 🦀 Example of spawning thread and
// waiting for it to finish its work.
use std::thread::spawn;
fn main() {
let work = || println!("Doing thread work"); // Define a Rust closure that will perform some work in a thread
let handle = spawn(work); // spawn() function kicks off new thread, using closure
_ = handle.join(); // .join() waits for thread to finish
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment