Skip to main content

RangeSet

Struct RangeSet 

Source
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

Source

pub fn new() -> Self

Create an empty RangeSet.

Source

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.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Number of individual values in the set.

Source

pub fn is_empty(&self) -> bool

Whether the set is empty.

Source

pub fn add_str(&mut self, s: &str)

Add a string element directly.

Source

pub fn add_int(&mut self, value: i64, pad: u32)

Add an integer element with optional zero-padding.

Source

pub fn remove_str(&mut self, s: &str)

Remove an element by string. Panics if not present.

Source

pub fn discard_str(&mut self, s: &str)

Remove an element by string if present (no error).

Source

pub fn contains_str(&self, s: &str) -> bool

Check if a string element is in the set.

Source

pub fn contains_int(&self, value: i64) -> bool

Check if an integer (unpadded) is in the set.

Source

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.

Source

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.

Source

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.

Source

pub fn sorted(&self) -> Vec<String>

Get sorted elements as owned strings.

Source

pub fn striter(&self) -> impl Iterator<Item = String>

Iterate as strings (owned).

Source

pub fn intiter(&self) -> impl Iterator<Item = i64>

Iterate as integer values.

Source

pub fn union(&self, other: &RangeSet) -> RangeSet

Return the union of two range sets.

Source

pub fn intersection(&self, other: &RangeSet) -> RangeSet

Return the intersection of two range sets.

Source

pub fn difference(&self, other: &RangeSet) -> RangeSet

Return the difference (self - other).

Source

pub fn symmetric_difference(&self, other: &RangeSet) -> RangeSet

Return the symmetric difference.

Source

pub fn update(&mut self, other: &RangeSet)

Update self to be the union with other.

Source

pub fn intersection_update(&mut self, other: &RangeSet)

Update self to be the intersection with other.

Source

pub fn difference_update(&mut self, other: &RangeSet)

Update self to be self - other.

Source

pub fn symmetric_difference_update(&mut self, other: &RangeSet)

Update self to be the symmetric difference with other.

Source

pub fn autostep(&self) -> Option<u32>

Get autostep value (user-facing: minimum node count, or None if disabled).

Source

pub fn set_autostep(&mut self, val: Option<u32>)

Set autostep value (user-facing: minimum node count, or None to disable).

Source

pub fn padding(&self) -> Option<usize>

Get the maximum padding value in the set.

Trait Implementations§

Source§

impl Clone for RangeSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RangeSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RangeSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for RangeSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RangeSet

Source§

fn eq(&self, other: &Self) -> bool

Equality follows Python’s set semantics (used by RangeSet.__eq__): only the contained elements are compared, not the autostep setting.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.