Skip to main content

Input

Struct Input 

Source
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

Source

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.

Source

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");
Source

pub fn from_boxed_reader(reader: Box<dyn Read>) -> Result<Self>

As Input::from_reader, for an already-boxed reader.

Source

pub fn from_path(path: &str) -> Result<Self>

Open a file at path for reading.

Source

pub fn from_stdin() -> Result<Self>

Read from process stdin.

Source

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.

Source

pub fn take_io_error(&mut self) -> Option<Error>

Take the recorded std::io::Error, leaving the slot empty. See Input::io_error.

Source

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.

Trait Implementations§

Source§

impl Drop for Input

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'a> From<Input> for MessageSource<'a>

Source§

fn from(input: Input) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Input

§

impl !Send for Input

§

impl !Sync for Input

§

impl !UnwindSafe for Input

§

impl Freeze for Input

§

impl Unpin for Input

§

impl UnsafeUnpin for Input

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.