pub fn add(a: i32, b: i32) -> i32 {
a + b
}
#[cfg(test)]
mod tests {
use std::fmt::Display;
fn make_adder(x: i32) -> impl Fn(i32) -> i32 {
move |y| x + y
}
enum List {
Cons(i32, Box<List>),
Nil,
}
use List::{Cons, Nil};
use once_cell::sync::Lazy;
use regex::Regex;
static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[^ @]+@[^ @]+.[^ @]+$").unwrap()
});
use parking_lot::Mutex;
use std::sync::Arc;
use std::thread;
fn main() {
let counter = Arc::new(Mutex::new(0));
use std::pin::Pin;
use std::future::Future;
async fn example() {
println!("Example future");
}
fn take_ownership(s: String) {
println!("Took ownership: {}", s);
} // s is dropped here
fn main() {
let message = String::from("hello");
use std::process::Command;
fn main() -> std::io::Result<()> {
let output = Command::new("ls")
.arg("-la")
.output()?;
use std::ops::Deref;
struct MyBox<T>(T);
impl<T> Deref for MyBox<T> {
type Target = T;
fn main() {
let mut numbers = Vec::new();
numbers.push(1);
numbers.push(2);
numbers.push(3);
use std::mem::MaybeUninit;
fn main() {
let mut uninit: MaybeUninit<i32> = MaybeUninit::uninit();
unsafe {
uninit.as_mut_ptr().write(42);
// build.rs
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let version = env!("CARGO_PKG_VERSION");
println!("cargo:rustc-env=BUILD_VERSION={}", version);