pub struct RangeSet { /* private fields */ }Expand description
An ordered set of integer string representations, supporting cluster
range notation like "1-10,15,20-30/2".
Implementations§
Source§impl RangeSet
impl RangeSet
Sourcepub fn parse(pattern: &str, autostep: Option<u32>) -> Result<Self>
pub fn parse(pattern: &str, autostep: Option<u32>) -> Result<Self>
Parse a range set from a string pattern like "1-4,6,8-12/2".
autostep is the user-facing autostep threshold (minimum element count
to trigger step folding). Pass None to disable.
Sourcepub fn from_optional_pattern(
pattern: Option<&str>,
autostep: Option<u32>,
) -> Result<Self>
pub fn from_optional_pattern( pattern: Option<&str>, autostep: Option<u32>, ) -> Result<Self>
Construct from an optional pattern, mirroring Python’s
RangeSet(pattern_or_None): None yields an empty set, while
Some("") is an error by design, exactly like RangeSet("").
This is the round-trip-safe reconstruction path for the empty set,
porting the upstream pickling fix (ClusterShell commit 9df4c5a):
Python’s RangeSet.__reduce__ stores None instead of "" when the
set is empty, so unpickling an empty RangeSet works again. In Rust
terms, serializing an empty set must produce None (not
Some(String::new())), and deserializing through this constructor
round-trips correctly.
Sourcepub fn add_range(&mut self, start: i64, stop: i64, step: i64, pad: u32)
pub fn add_range(&mut self, start: i64, stop: i64, step: i64, pad: u32)
Add a range of integers [start, stop) with given step and padding.
Sourcepub fn add_int(&mut self, value: i64, pad: u32)
pub fn add_int(&mut self, value: i64, pad: u32)
Add an integer element with optional zero-padding.
Sourcepub fn remove_str(&mut self, s: &str)
pub fn remove_str(&mut self, s: &str)
Remove an element by string. Panics if not present.
Sourcepub fn discard_str(&mut self, s: &str)
pub fn discard_str(&mut self, s: &str)
Remove an element by string if present (no error).
Sourcepub fn contains_str(&self, s: &str) -> bool
pub fn contains_str(&self, s: &str) -> bool
Check if a string element is in the set.
Sourcepub fn contains_int(&self, value: i64) -> bool
pub fn contains_int(&self, value: i64) -> bool
Check if an integer (unpadded) is in the set.
Sourcepub fn index(&self, value: u64) -> Option<usize>
pub fn index(&self, value: u64) -> Option<usize>
Return the zero-based position of value in sorted order, or None
if the element is absent.
Ports Python’s RangeSet.index() (ClusterShell commit 484d230), the
reverse operation of RangeSet.__getitem__, behaving like
list.index() (absent element -> None here, ValueError there).
Like the Python integer form, the value is looked up as its plain
decimal string, so zero-padding is significant: 9 is not a member
of RangeSet("08-10") and yields None. Negative values cannot be
expressed through this u64 signature.
Sourcepub fn index_str(&self, key: &str) -> Option<usize>
pub fn index_str(&self, key: &str) -> Option<usize>
String form of RangeSet::index, matching Python’s string
argument form where zero-padding is significant.
Sourcepub fn index_str_within(
&self,
key: &str,
start: isize,
stop: Option<isize>,
) -> Option<usize>
pub fn index_str_within( &self, key: &str, start: isize, stop: Option<isize>, ) -> Option<usize>
RangeSet::index_str restricted to a search window, mirroring
Python’s optional start/stop arguments of RangeSet.index()
(list.index() semantics; negative bounds count from the end).
Returns None when the element is absent or its position falls
outside the window.
Sourcepub fn intersection(&self, other: &RangeSet) -> RangeSet
pub fn intersection(&self, other: &RangeSet) -> RangeSet
Return the intersection of two range sets.
Sourcepub fn difference(&self, other: &RangeSet) -> RangeSet
pub fn difference(&self, other: &RangeSet) -> RangeSet
Return the difference (self - other).
Sourcepub fn symmetric_difference(&self, other: &RangeSet) -> RangeSet
pub fn symmetric_difference(&self, other: &RangeSet) -> RangeSet
Return the symmetric difference.
Sourcepub fn intersection_update(&mut self, other: &RangeSet)
pub fn intersection_update(&mut self, other: &RangeSet)
Update self to be the intersection with other.
Sourcepub fn difference_update(&mut self, other: &RangeSet)
pub fn difference_update(&mut self, other: &RangeSet)
Update self to be self - other.
Sourcepub fn symmetric_difference_update(&mut self, other: &RangeSet)
pub fn symmetric_difference_update(&mut self, other: &RangeSet)
Update self to be the symmetric difference with other.
Sourcepub fn autostep(&self) -> Option<u32>
pub fn autostep(&self) -> Option<u32>
Get autostep value (user-facing: minimum node count, or None if disabled).
Sourcepub fn set_autostep(&mut self, val: Option<u32>)
pub fn set_autostep(&mut self, val: Option<u32>)
Set autostep value (user-facing: minimum node count, or None to disable).