New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
RUSTExample pasteCreated 2026-07-311 viewNo expiry

Rust error propagation example

Raw New paste
rustRead-only
1
use std::{fs, io, path::Path};

fn read_nonempty(path: &Path) -> Result<String, io::Error> {
    let content = fs::read_to_string(path)?;
    if content.trim().is_empty() {
        return Err(io::Error::new(
            io::ErrorKind::InvalidData,
            "file is empty",
        ));
    }
    Ok(content)
}
Report abuse

Paste details

Visibility
Public
Size
312 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.