use std::rc::Rc;
use std::cell::RefCell;
fn main() {
let data = Rc::new(RefCell::new(vec![1, 2, 3]));
enum List {
Cons(i32, Box<List>),
Nil,
}
use List::{Cons, Nil};
enum Status {
Ok,
Error(String),
Pending,
}
fn main() {
let numbers = vec![1, 2, 3, 4, 5];
let sum: i32 = numbers
.iter()
.filter(|&&x| x % 2 == 0)
fn divide(a: i32, b: i32) -> Option<i32> {
if b == 0 {
None
} else {
Some(a / b)
}
#[derive(Debug, Clone, PartialEq)]
struct Point {
x: i32,
y: i32,
}
use std::fmt::Display;
fn print_it<T: Display>(value: T) {
println!("Value: {}", value);
}
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
let handle = tokio::spawn(async {
sleep(Duration::from_millis(100)).await;
use tokio::time::{sleep, Duration};
async fn fetch_data() -> String {
sleep(Duration::from_millis(100)).await;
"data".to_string()
}
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
use std::sync::{Arc, Mutex};
use std::thread;
fn main() {
let counter = Arc::new(Mutex::new(0));
let mut handles = vec![];
struct Config<'a> {
name: &'a str,
value: &'a str,
}
fn parse_config(line: &str) -> Config {