pub struct TrySegmentError { /* private fields */ }Expand description
An error that occurs when trying to create a segment with an invalid range.
This error indicates that the requested range extends beyond the buffer’s boundaries or is otherwise invalid (e.g., start > end). The original buffer remains unchanged.
§Examples
let data = b"Hello";
let buf = &data[..];
// Range extends beyond buffer
match buf.try_segment(2..10) {
Err(e) => {
assert_eq!(e.start(), 2);
assert_eq!(e.end(), 10);
assert_eq!(e.available(), 5);
}
_ => panic!("Expected error"),
}
// Invalid range (start > end)
assert!(buf.try_segment(4..2).is_err());Implementations§
Source§impl TrySegmentError
impl TrySegmentError
Sourcepub const fn new(start: usize, end: usize, available: usize) -> Self
pub const fn new(start: usize, end: usize, available: usize) -> Self
Creates a new TrySegmentError.
§Panics
In debug builds, panics if the range is valid (would not be an error) or the available bytes are less than the requested range.
Sourcepub const fn available(&self) -> usize
pub const fn available(&self) -> usize
Returns the total number of bytes available in the buffer.
Sourcepub const fn requested(&self) -> usize
pub const fn requested(&self) -> usize
Returns the length of the requested range.
Returns 0 if start > end (invalid range).
Sourcepub const fn is_inverted(&self) -> bool
pub const fn is_inverted(&self) -> bool
Returns whether the range itself is invalid (start > end).
Trait Implementations§
Source§impl Clone for TrySegmentError
impl Clone for TrySegmentError
Source§fn clone(&self) -> TrySegmentError
fn clone(&self) -> TrySegmentError
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 TrySegmentError
impl Debug for TrySegmentError
Source§impl Display for TrySegmentError
impl Display for TrySegmentError
Source§impl Error for TrySegmentError
impl Error for TrySegmentError
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<TrySegmentError> for Error
impl From<TrySegmentError> for Error
Source§fn from(e: TrySegmentError) -> Self
fn from(e: TrySegmentError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for TrySegmentError
impl PartialEq for TrySegmentError
impl Copy for TrySegmentError
impl Eq for TrySegmentError
impl StructuralPartialEq for TrySegmentError
Auto Trait Implementations§
impl Freeze for TrySegmentError
impl RefUnwindSafe for TrySegmentError
impl Send for TrySegmentError
impl Sync for TrySegmentError
impl Unpin for TrySegmentError
impl UnwindSafe for TrySegmentError
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