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§
Sourcefn truncate(&mut self, new_len: usize) -> Result<(), Error>
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]);