pub trait BorrowedInput<'a>: Input {
// Required method
fn slice_borrowed(&self, start: usize, end: usize) -> Option<&'a str>;
}Expand description
A trait for inputs that can provide borrowed slices with a specific lifetime.
This trait enables zero-copy (Cow::Borrowed) token values for inputs that keep a stable
backing string. The key difference from Input::slice_bytes is that this method returns
a slice with the input’s original lifetime 'a, not tied to &self.
For inputs that support zero-copy (like str::StrInput), this returns Some(&'a str).
For streaming inputs that don’t have stable backing storage, this returns None.
Required Methods§
Sourcefn slice_borrowed(&self, start: usize, end: usize) -> Option<&'a str>
fn slice_borrowed(&self, start: usize, end: usize) -> Option<&'a str>
Return a borrowed slice of the underlying source between two byte offsets.
Unlike Input::slice_bytes, this returns a slice with the input’s lifetime 'a,
allowing the slice to outlive the borrow of &self.
start and end are byte offsets as returned by Input::byte_offset. The interval is
half-open: [start, end).
Returns None if the input does not support zero-copy slicing.
§Panics
Implementations may panic in debug builds if start is greater than end or end is past
the end of the underlying source.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<'a> BorrowedInput<'a> for StrInput<'a>
impl<T: Iterator<Item = Result<char, ErrorKind>>> BorrowedInput<'static> for FallibleBufferedInput<T>
FallibleBufferedInput is a streaming input and cannot provide stable borrowed slices.
impl<T: Iterator<Item = char>> BorrowedInput<'static> for BufferedInput<T>
BufferedInput does not support zero-copy slicing since it’s a streaming input
without stable backing storage.