[][src]Struct multipart::server::save::BufReader

pub struct BufReader<R, P = StdPolicy> { /* fields omitted */ }

A drop-in replacement for std::io::BufReader with more functionality.

Original method names/signatures and implemented traits are left untouched, making replacement as simple as swapping the import of the type.

By default this type implements the behavior of its std counterpart: it only reads into the buffer when it is empty.

To change this type's behavior, change the policy with .set_policy() using a type from the policy module or your own implementation of ReaderPolicy.

Policies that perform alternating reads and consumes without completely emptying the buffer may benefit from using a ringbuffer via the new_ringbuf() and with_capacity_ringbuf() constructors. Ringbuffers are only available on supported platforms with the slice-deque feature and have some other caveats; see the crate root docs for more details.

Implementations

impl<R> BufReader<R, StdPolicy>[src]

pub fn new(inner: R) -> BufReader<R, StdPolicy>

Notable traits for BufReader<R, P>

impl<R, P> Read for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
[src]

Create a new BufReader wrapping inner, utilizing a buffer of default capacity and the default ReaderPolicy.

pub fn with_capacity(cap: usize, inner: R) -> BufReader<R, StdPolicy>

Notable traits for BufReader<R, P>

impl<R, P> Read for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
[src]

Create a new BufReader wrapping inner, utilizing a buffer with a capacity of at least cap bytes and the default ReaderPolicy.

The actual capacity of the buffer may vary based on implementation details of the global allocator.

pub fn with_buffer(buf: Buffer, inner: R) -> BufReader<R, StdPolicy>

Notable traits for BufReader<R, P>

impl<R, P> Read for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
[src]

Wrap inner with an existing Buffer instance and the default ReaderPolicy.

Note

Does not clear the buffer first! If there is data already in the buffer then it will be returned in read() and fill_buf() ahead of any data from inner.

impl<R, P> BufReader<R, P>[src]

pub fn set_policy<P_>(self, policy: P_) -> BufReader<R, P_>

Notable traits for BufReader<R, P>

impl<R, P> Read for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
where
    P_: ReaderPolicy
[src]

Apply a new ReaderPolicy to this BufReader, returning the transformed type.

pub fn policy_mut(&mut self) -> &mut P[src]

Mutate the current ReaderPolicy in-place.

If you want to change the type, use .set_policy().

pub fn policy(&self) -> &P[src]

Inspect the current ReaderPolicy.

pub fn make_room(&mut self)[src]

Move data to the start of the buffer, making room at the end for more reading.

This is a no-op with the *_ringbuf() constructors (requires slice-deque feature).

pub fn reserve(&mut self, additional: usize)[src]

Ensure room in the buffer for at least additional bytes. May not be quite exact due to implementation details of the buffer's allocator.

pub fn buffer(&self) -> &[u8][src]

Get the section of the buffer containing valid data; may be empty.

Call .consume() to remove bytes from the beginning of this section.

pub fn buf_len(&self) -> usize[src]

Get the current number of bytes available in the buffer.

pub fn capacity(&self) -> usize[src]

Get the total buffer capacity.

pub fn get_ref(&self) -> &R[src]

Get an immutable reference to the underlying reader.

pub fn get_mut(&mut self) -> &mut R[src]

Get a mutable reference to the underlying reader.

Note

Reading directly from the underlying reader is not recommended, as some data has likely already been moved into the buffer.

pub fn into_inner(self) -> R[src]

Consume self and return the inner reader only.

pub fn into_inner_with_buffer(self) -> (R, Buffer)[src]

Consume self and return both the underlying reader and the buffer.

See also: BufReader::unbuffer()

pub fn unbuffer(self) -> Unbuffer<R>[src]

Consume self and return an adapter which implements Read and will empty the buffer before reading directly from the underlying reader.

impl<R, P> BufReader<R, P> where
    R: Read
[src]

pub fn read_into_buf(&mut self) -> Result<usize, Error>[src]

Unconditionally perform a read into the buffer.

Does not invoke ReaderPolicy methods.

If the read was successful, returns the number of bytes read.

pub fn boxed<'a>(self) -> BufReader<Box<dyn Read + 'a, Global>, P>

Notable traits for BufReader<R, P>

impl<R, P> Read for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
where
    R: 'a, 
[src]

Box the inner reader without losing data.

Trait Implementations

impl<R, P> BufRead for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
[src]

impl<R, P> Debug for BufReader<R, P> where
    R: Debug,
    P: Debug
[src]

impl<R, P> Read for BufReader<R, P> where
    R: Read,
    P: ReaderPolicy
[src]

impl<R, P> Seek for BufReader<R, P> where
    R: Seek,
    P: ReaderPolicy
[src]

pub fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>[src]

Seek to an ofPet, in bytes, in the underlying reader.

The position used for seeking with SeekFrom::Current(_) is the position the underlying reader would be at if the BufReader had no internal buffer.

Seeking always discards the internal buffer, even if the seek position would otherwise fall within it. This guarantees that calling .unwrap() immediately after a seek yields the underlying reader at the same position.

See std::io::Seek for more details.

Note: In the edge case where you're seeking with SeekFrom::Current(n) where n minus the internal buffer length underflows an i64, two seeks will be performed instead of one. If the second seek returns Err, the underlying reader will be left at the same position it would have if you seeked to SeekFrom::Current(0).

Auto Trait Implementations

impl<R, P> RefUnwindSafe for BufReader<R, P> where
    P: RefUnwindSafe,
    R: RefUnwindSafe
[src]

impl<R, P> Send for BufReader<R, P> where
    P: Send,
    R: Send
[src]

impl<R, P> Sync for BufReader<R, P> where
    P: Sync,
    R: Sync
[src]

impl<R, P> Unpin for BufReader<R, P> where
    P: Unpin,
    R: Unpin
[src]

impl<R, P> UnwindSafe for BufReader<R, P> where
    P: UnwindSafe,
    R: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DebugAny for T where
    T: Any + Debug

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<R> ReadBytesExt for R where
    R: Read + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,