pub struct TryPutError { /* 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_put_u64_le(0x123456789ABCDEF0) {
Err(e) => {
// Caller knows exactly how much space is needed
assert_eq!(e.requested().get(), 8);
assert_eq!(e.available(), 4);
}
_ => panic!("Expected error"),
}Implementations§
Source§impl TryPutError
impl TryPutError
Sourcepub const fn new(requested: NonZeroUsize, available: usize) -> Self
pub const fn new(requested: NonZeroUsize, available: usize) -> Self
Creates a new TryPutError with the requested and available bytes.
§Panics
- If
requested <= available(this would not be an error condition). - The
requestedvalue must be a non-zero.
Sourcepub const fn requested(&self) -> NonZeroUsize
pub const fn requested(&self) -> NonZeroUsize
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 TryPutError
impl Clone for TryPutError
Source§fn clone(&self) -> TryPutError
fn clone(&self) -> TryPutError
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 TryPutError
impl Debug for TryPutError
Source§impl Display for TryPutError
impl Display for TryPutError
Source§impl Error for TryPutError
impl Error for TryPutError
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<TryPutError> for Error
impl From<TryPutError> for Error
Source§fn from(e: TryPutError) -> Self
fn from(e: TryPutError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for TryPutError
impl PartialEq for TryPutError
impl Copy for TryPutError
impl Eq for TryPutError
impl StructuralPartialEq for TryPutError
Auto Trait Implementations§
impl Freeze for TryPutError
impl RefUnwindSafe for TryPutError
impl Send for TryPutError
impl Sync for TryPutError
impl Unpin for TryPutError
impl UnwindSafe for TryPutError
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