enum Status {
Ok,
Error(String),
Pending,
}
# Install
cargo install cargo-expand
# Expand entire crate
cargo expand
use std::collections::HashMap;
fn main() {
let mut scores = HashMap::new();
scores.insert("Alice", 10);
scores.insert("Bob", 20);
use std::fs;
use std::num::ParseIntError;
fn read_port(path: &str) -> Result<u16, Box<dyn std::error::Error>> {
let contents = fs::read_to_string(path)?;
let port: u16 = contents.trim().parse()?;
use std::fs;
use std::io::Result;
fn main() -> Result<()> {
let contents = fs::read_to_string("input.txt")?;
println!("File contents: {}", contents);
use std::fs::File;
use std::io::{BufRead, BufReader, Result};
fn main() -> Result<()> {
let file = File::open("input.txt")?;
let reader = BufReader::new(file);
fn greet(name: &str) {
println!("Hello, {}", name);
}
fn main() {
let owned = String::from("Alice");
use color_eyre::Result;
fn might_fail() -> Result<()> {
Err(color_eyre::eyre::eyre!("Something went wrong"))
}
use std::mem;
fn main() {
let mut x = 5;
let mut y = 10;
use std::rc::Rc;
use std::cell::RefCell;
fn main() {
let data = Rc::new(RefCell::new(vec![1, 2, 3]));
struct Logger {
name: String,
}
impl Drop for Logger {
fn drop(&mut self) {
[package]
name = "my-app"
version = "0.1.0"
[dependencies]
tokio = "1"