Truncate

Trait Truncate 

Source
pub trait Truncate {
    // Required method
    fn truncate(&mut self, new_len: usize) -> Result<(), Error>;
}
Expand description

A trait for IO objects that can be shortened.

See the documentation comments on individual implementations for some potentially important notes on their specific behaviors.

Required Methods§

Source

fn truncate(&mut self, new_len: usize) -> Result<(), Error>

Truncate the object to the given new length in bytes.

The behavior when new_len is larger than the current length of the object is unspecified. Implementations may choose to panic or extend the data in some way.

§Example
let mut v: &[u8] = &[0, 1, 2, 3];
v.truncate(3).unwrap();
assert_eq!(v, &[0, 1, 2]);

Implementations on Foreign Types§

Source§

impl Truncate for Vec<u8>

Source§

fn truncate(&mut self, new_len: usize) -> Result<(), Error>

Shortens the Vec or returns an error if the length would be larger than the current length.

Source§

impl Truncate for File

Source§

fn truncate(&mut self, new_len: usize) -> Result<(), Error>

Delegates to File::set_len.

Source§

impl<'a> Truncate for &'a [u8]

Source§

fn truncate(&mut self, new_len: usize) -> Result<(), Error>

Shortens the slice or returns and error if the length would be larger than the current length.

Source§

impl<T> Truncate for &mut T
where T: Truncate,

Source§

fn truncate(&mut self, new_len: usize) -> Result<(), Error>

Source§

impl<T> Truncate for Cursor<T>
where T: Truncate,

Source§

fn truncate(&mut self, new_len: usize) -> Result<(), Error>

Delegates to the contained Truncate impl. The cursor will be moved to the end of the data if it lies in the truncated area.

Implementors§