knarkzel 0.1.0

Useful functions and re-exports missing in std
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// Re-exports
pub use ureq;
pub use regex;

/// Minimal eyre-like Result type
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Reads argument either as a HTTP-request (starts with `http://` or `https://`) or a file
pub fn slurp<T: AsRef<str>>(argument: T) -> Result<String> {
    let destination = argument.as_ref();
    let body = if destination.starts_with("http://") || destination.starts_with("https://") {
        ureq::get(destination).call()?.into_string()?
    } else {
        std::fs::read_to_string(destination)?
    };
    Ok(body)
}