Struct offset_string::OffsetString
source · pub struct OffsetString(_);
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<OffsetString> for OffsetString
impl PartialEq<OffsetString> for OffsetString
source§fn eq(&self, other: &OffsetString) -> bool
fn eq(&self, other: &OffsetString) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.