pub struct TakeBytes { /* private fields */ }Expand description
A source of bytes from either stdin or a file path.
TakeBytes implements FromStr, making it easy to use with clap’s derive API.
When parsing:
"-"is interpreted as stdin- Any other string 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,
}§Programmatic Construction
use take_bytes::TakeBytes;
// Read from stdin
let stdin_input = TakeBytes::stdin();
// Read from a file (note: file must exist when calling from_str)
// let file_input = TakeBytes::file("/path/to/file");Implementations§
Source§impl TakeBytes
impl TakeBytes
Sourcepub fn stdin() -> Self
pub fn stdin() -> Self
Create a TakeBytes that reads from stdin.
§Example
use take_bytes::TakeBytes;
let input = TakeBytes::stdin();Sourcepub fn file(path: PathBuf) -> Self
pub fn file(path: PathBuf) -> Self
Create a TakeBytes that reads from a file.
Note: This does not check if the file exists. The check happens
when you call try_into_bytes.
§Example
use take_bytes::TakeBytes;
use std::path::PathBuf;
let input = TakeBytes::file(PathBuf::from("/path/to/file"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for TakeBytes
impl RefUnwindSafe for TakeBytes
impl Send for TakeBytes
impl Sync for TakeBytes
impl Unpin for TakeBytes
impl UnwindSafe for TakeBytes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more