pub struct TryWriteError { /* private fields */ }Expand description
An error that occurs when trying to write data to a buffer with insufficient space.
This error indicates that a write operation failed because the buffer does not have enough remaining capacity to hold the data.
This error is particularly useful for Sans-I/O designs as it provides exact information about space requirements, allowing the caller to allocate a larger buffer and retry:
let mut small_buf = [0u8; 4];
let mut writer = &mut small_buf[..];
match writer.try_write_u64_le(0x123456789ABCDEF0) {
Err(e) => {
// Caller knows exactly how much space is needed
assert_eq!(e.requested(), 8);
assert_eq!(e.available(), 4);
println!("Need {} more bytes", e.shortage());
}
_ => panic!("Expected error"),
}Implementations§
Source§impl TryWriteError
impl TryWriteError
Sourcepub const fn new(requested: usize, available: usize) -> Self
pub const fn new(requested: usize, available: usize) -> Self
Creates a new TryWriteError with the requested and available bytes.
§Panics
- In debug builds, panics if
requested <= available(this would not be an error condition). - The
requestedvalue must be a non-zero.
Sourcepub const fn requested(&self) -> usize
pub const fn requested(&self) -> usize
Returns the number of bytes requested for the operation.
This is the minimum number of bytes needed for the operation to succeed.
Trait Implementations§
Source§impl Clone for TryWriteError
impl Clone for TryWriteError
Source§fn clone(&self) -> TryWriteError
fn clone(&self) -> TryWriteError
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TryWriteError
impl Debug for TryWriteError
Source§impl Display for TryWriteError
impl Display for TryWriteError
Source§impl Error for TryWriteError
impl Error for TryWriteError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<TryWriteError> for Error
impl From<TryWriteError> for Error
Source§fn from(e: TryWriteError) -> Self
fn from(e: TryWriteError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for TryWriteError
impl PartialEq for TryWriteError
impl Copy for TryWriteError
impl Eq for TryWriteError
impl StructuralPartialEq for TryWriteError
Auto Trait Implementations§
impl Freeze for TryWriteError
impl RefUnwindSafe for TryWriteError
impl Send for TryWriteError
impl Sync for TryWriteError
impl Unpin for TryWriteError
impl UnwindSafe for TryWriteError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more