Function selection_from_one

Source
pub fn selection_from_one<'a, R>(
    shape: &Shape,
    label: &'a str,
    rng: R,
) -> Result<Selection, ShapeError>
where R: Into<Range>,
Expand description

Construct a Selection from a Shape and a single labeled constraint.

This function produces a multidimensional selection expression that is structurally aligned with the shape. It applies the given range to the named dimension, and fills all preceding dimensions with all to maintain alignment. Trailing dimensions are left unconstrained.

§Arguments

  • shape: The labeled shape describing the coordinate space.
  • label: The name of the dimension to constrain.
  • rng: The range to apply in the selected dimension.

§Errors

Returns ShapeError::InvalidLabels if the label is not present in the shape.

§Example

use ndslice::shape;
use ndslice::selection::selection_from_one;

let shape = shape!(zone = 2, host = 4, gpu = 8);
let sel = selection_from_one(&shape, "host", 1..3).unwrap();
assert_eq!(format!("{sel:?}"), "All(Range(Range(1, Some(3), 1), True))"); // corresponds to (*, 1..3, *)