pub struct Input { /* private fields */ }Expand description
Owns an rnp_input_t for the lifetime of this value.
Construct with Input::from_memory, Input::from_path,
Input::from_stdin, or Input::from_reader (any
std::io::Read). Operations consume inputs through their
*_with_input constructors.
When the input is reader-backed, the underlying std::io::Error of a
failed read is retrievable via Input::io_error after the enclosing
operation fails — librnp itself only reports a generic
RNP_ERROR_READ.
Implementations§
Source§impl Input
impl Input
Sourcepub fn from_memory(bytes: &[u8]) -> Result<Self>
pub fn from_memory(bytes: &[u8]) -> Result<Self>
Wrap memory as an input. The bytes are copied on the C side, so the
caller’s slice does not need to outlive the Input.
Sourcepub fn from_reader(reader: impl Read + 'static) -> Result<Self>
pub fn from_reader(reader: impl Read + 'static) -> Result<Self>
Stream from any std::io::Read.
The reader is read lazily by librnp while the enclosing operation
runs, so nothing is buffered in memory beyond librnp’s own chunk
size. The reader must not be used elsewhere while the Input
exists. If a read fails, the operation fails and the original
std::io::Error is available via Input::io_error.
let reader = std::io::Cursor::new(b"stream me".to_vec());
let input = Input::from_reader(reader).unwrap();
let mut output = Output::to_memory().unwrap();
output.pipe(&input).unwrap();
assert_eq!(output.into_bytes().unwrap(), b"stream me");Sourcepub fn from_boxed_reader(reader: Box<dyn Read>) -> Result<Self>
pub fn from_boxed_reader(reader: Box<dyn Read>) -> Result<Self>
As Input::from_reader, for an already-boxed reader.
Sourcepub fn from_stdin() -> Result<Self>
pub fn from_stdin() -> Result<Self>
Read from process stdin.
Sourcepub fn io_error(&self) -> Option<&Error>
pub fn io_error(&self) -> Option<&Error>
The std::io::Error recorded when a reader-backed input’s read
callback last failed, if any. None for non-reader-backed inputs
and when no read has failed.
Sourcepub fn take_io_error(&mut self) -> Option<Error>
pub fn take_io_error(&mut self) -> Option<Error>
Take the recorded std::io::Error, leaving the slot empty. See
Input::io_error.
Sourcepub fn into_reader(self) -> Option<(Box<dyn Read>, Option<Error>)>
pub fn into_reader(self) -> Option<(Box<dyn Read>, Option<Error>)>
Reclaim the reader from a reader-backed Input, destroying the
C handle first (which stops any further callbacks).
Returns None if this input is not reader-backed. If the reader
panicked during an operation, that panic resumes here. The second
tuple element is the deferred read error, if any.