QuickSnip
Browse
Tags
+ New
← Back to snippet
Edit snippet
Title
Description
(optional)
Idiomatic Rust file read with proper error propagation.
Language
JavaScript
TypeScript
JSX
TSX
Python
Go
Rust
Bash
SQL
CSS
HTML
JSON
YAML
Markdown
Tags
Loading tags…
Code
use std::fs; use std::io; fn read_config(path: &str) -> io::Result<String> { let contents = fs::read_to_string(path)?; Ok(contents) } fn main() { match read_config("config.toml") { Ok(text) => println!("{text}"), Err(e) => eprintln!("error: {e}"), } }
Update snippet
Cancel