pub struct OffsetString(/* private fields */);
Expand description
A compact representation of a set of unsigned integer ranges.
The primary use case is succinctly encoding a large set of Unicode code points in JSON.
If the set of ranges is
[1..=3, 8..=9, 13..=13, 18..=20]
the OffsetString
will be
"1+2,5+1,4,4+3"
In each entry, the first number is the offset from the end of the previous range. If the current range has length > 1, then there’s a ‘+x’ that shows how much to add to get the upper bound of the range. Note that the range [13, 14) has length 1, so it doesn’t get a plus suffix.
Implementations§
Source§impl OffsetString
impl OffsetString
Sourcepub fn new<T: AsRef<str>>(source: T) -> Result<OffsetString, Error>
pub fn new<T: AsRef<str>>(source: T) -> Result<OffsetString, Error>
Tries to construct a new OffsetString
from a string.
This method performs basic validation on whether the string is syntactically valid and does
not contain any redundantly short ranges. Returns an Error
if validation fails.
Sourcepub fn iter_ranges<'a>(
&'a self,
) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
pub fn iter_ranges<'a>( &'a self, ) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
Iterate over the numeric ranges in the collection.
Trait Implementations§
Source§impl Debug for OffsetString
impl Debug for OffsetString
Source§impl<'de> Deserialize<'de> for OffsetString
impl<'de> Deserialize<'de> for OffsetString
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&CharCollection> for OffsetString
impl From<&CharCollection> for OffsetString
Source§fn from(value: &CharCollection) -> OffsetString
fn from(value: &CharCollection) -> OffsetString
Converts to this type from the input type.
Source§impl From<&CharSet> for OffsetString
impl From<&CharSet> for OffsetString
Source§fn from(char_set: &CharSet) -> OffsetString
fn from(char_set: &CharSet) -> OffsetString
Converts to this type from the input type.
Source§impl From<CharCollection> for OffsetString
impl From<CharCollection> for OffsetString
Source§fn from(value: CharCollection) -> OffsetString
fn from(value: CharCollection) -> OffsetString
Converts to this type from the input type.
Source§impl From<CharSet> for OffsetString
impl From<CharSet> for OffsetString
Source§fn from(value: CharSet) -> OffsetString
fn from(value: CharSet) -> OffsetString
Converts to this type from the input type.
Source§impl From<OffsetString> for String
impl From<OffsetString> for String
Source§fn from(value: OffsetString) -> String
fn from(value: OffsetString) -> String
Converts to this type from the input type.
Source§impl PartialEq for OffsetString
impl PartialEq for OffsetString
Source§impl Serialize for OffsetString
impl Serialize for OffsetString
Source§impl TryFrom<&OffsetString> for CharCollection
impl TryFrom<&OffsetString> for CharCollection
Source§impl TryFrom<&OffsetString> for CharSet
impl TryFrom<&OffsetString> for CharSet
Source§impl TryFrom<&str> for OffsetString
impl TryFrom<&str> for OffsetString
Source§impl TryFrom<OffsetString> for CharCollection
impl TryFrom<OffsetString> for CharCollection
Source§impl TryFrom<OffsetString> for CharSet
impl TryFrom<OffsetString> for CharSet
Source§impl TryFrom<String> for OffsetString
impl TryFrom<String> for OffsetString
impl Eq for OffsetString
impl StructuralPartialEq for OffsetString
Auto Trait Implementations§
impl Freeze for OffsetString
impl RefUnwindSafe for OffsetString
impl Send for OffsetString
impl Sync for OffsetString
impl Unpin for OffsetString
impl UnwindSafe for OffsetString
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