Trait io_truncate::Truncate[][src]

pub trait Truncate {
    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

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

Delegates to File::set_len.

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

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

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