Expand description
§take_bytes
A lightweight utility for reading input from stdin or a file path, designed for seamless integration with clap’s derive API.
§Overview
take_bytes provides a TakeBytes type that implements FromStr, allowing
it to be used directly as a clap argument type. When the user passes "-", input
is read from stdin; otherwise, the argument is treated as a file path.
§Example
ⓘ
use clap::Parser;
use take_bytes::TakeBytes;
#[derive(Parser)]
struct Cli {
/// Input file or "-" for stdin
#[arg(default_value = "-")]
input: TakeBytes,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
let contents = cli.input.try_into_bytes()?;
println!("Read {} bytes", contents.len());
Ok(())
}Structs§
- Take
Bytes - A source of bytes from either stdin or a file path.
Enums§
- Decoding
Error - Errors that can occur when decoding input.
- Source
- Represents the source of input data.
Functions§
- decode_
utf8_ string - Read the entire contents from the input source and decode as UTF-8.
- read_
as_ bytes - Read the entire contents from the input source as bytes.