pub enum IndexedCow {
Borrowed {
start: usize,
end: usize,
},
Owned(String),
}
Expand description
A span of text that can be either owned, or indexed in another String.
Variants§
Implementations§
Source§impl IndexedCow
impl IndexedCow
Sourcepub fn subcow(&self, range: Range<usize>) -> IndexedCow
pub fn subcow(&self, range: Range<usize>) -> IndexedCow
Gets a new IndexedCow
for the given range.
The given range is relative to this span.
Sourcepub fn as_borrowed(&self) -> Option<(usize, usize)>
pub fn as_borrowed(&self) -> Option<(usize, usize)>
Return the (start, end)
indexes if self
is IndexedCow::Borrowed
.
Sourcepub fn as_borrowed_mut(&mut self) -> Option<(&mut usize, &mut usize)>
pub fn as_borrowed_mut(&mut self) -> Option<(&mut usize, &mut usize)>
Return the (start, end)
indexes if self
is IndexedCow::Borrowed
.
Sourcepub fn as_owned(&self) -> Option<&str>
pub fn as_owned(&self) -> Option<&str>
Returns the embedded text content if self
is IndexedCow::Owned
.
Sourcepub fn from_str(value: &str, source: &str) -> IndexedCow
pub fn from_str(value: &str, source: &str) -> IndexedCow
Returns an indexed view of the given string.
Note: it is assumed cow
, if borrowed, is a substring of source
.
Sourcepub fn from_cow(cow: Cow<'_, str>, source: &str) -> IndexedCow
pub fn from_cow(cow: Cow<'_, str>, source: &str) -> IndexedCow
Returns an indexed view of the given item.
Note: it is assumed cow
, if borrowed, is a substring of source
.
Sourcepub fn offset(&mut self, offset: usize)
pub fn offset(&mut self, offset: usize)
If self
is borrowed, offset its indices by the given value.
Useful to update spans when concatenating sources. This span will now
point to text offset
further in the source.
Sourcepub fn rev_offset(&mut self, offset: usize)
pub fn rev_offset(&mut self, offset: usize)
If self
is borrowed, offset its indices back by the given value.
Useful to update spans when removing a prefix from the source.
This span will now point to text offset
closer to the start of the source.
This span may become empty as a result.
Trait Implementations§
Source§impl<T> AsRef<IndexedCow> for IndexedSpan<T>
impl<T> AsRef<IndexedCow> for IndexedSpan<T>
Source§fn as_ref(&self) -> &IndexedCow
fn as_ref(&self) -> &IndexedCow
Source§impl Clone for IndexedCow
impl Clone for IndexedCow
Source§fn clone(&self) -> IndexedCow
fn clone(&self) -> IndexedCow
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for IndexedCow
impl Debug for IndexedCow
Source§impl Hash for IndexedCow
impl Hash for IndexedCow
Source§impl PartialEq for IndexedCow
impl PartialEq for IndexedCow
impl Eq for IndexedCow
impl StructuralPartialEq for IndexedCow
Auto Trait Implementations§
impl Freeze for IndexedCow
impl RefUnwindSafe for IndexedCow
impl Send for IndexedCow
impl Sync for IndexedCow
impl Unpin for IndexedCow
impl UnwindSafe for IndexedCow
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.