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 {
fn calculate_length(s: &String) -> usize {
s.len()
}
fn append_suffix(s: &mut String) {
s.push_str(" world");
fn take_ownership(s: String) {
println!("Took ownership: {}", s);
} // s is dropped here
fn main() {
let message = String::from("hello");
use anyhow::{Context, Result};
use std::fs;
fn load_config(path: &str) -> Result<String> {
fs::read_to_string(path)
.with_context(|| format!("failed to read config from {}", path))
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("file not found: {0}")]
NotFound(String),