pub struct Threading { /* private fields */ }Expand description
Threading in a weaving draft. 1 thread can only be on one shaft
Implementations§
Source§impl Threading
impl Threading
Sourcepub fn new(shaft_count: u32, threading: Vec<u32>) -> Self
pub fn new(shaft_count: u32, threading: Vec<u32>) -> Self
Constructs a new threading, verifying that the shaft_count is respected.
§Panics
If there are threads outside the shaft count
Sourcepub fn splice<R>(
&mut self,
range: R,
replace_with: &[u32],
) -> Result<Vec<u32>, usize>where
R: RangeBounds<usize>,
pub fn splice<R>(
&mut self,
range: R,
replace_with: &[u32],
) -> Result<Vec<u32>, usize>where
R: RangeBounds<usize>,
Based on Vec::splice, it splices the given sequence into the given range. It validates that
the elements in replace_with are inside the shaft bounds, and it returns the replaced elements.
§Examples
let mut threading = Threading::new(4, vec![1,2,3,4]);
let removed = threading.splice(1..3, &[4,3,4,1]).unwrap();
assert_eq!(threading, Threading::new(4, vec![1,4,3,4,1,4]));
assert_eq!(removed, vec![2,3]);
let error = threading.splice(1..3, &[5]).unwrap_err();
assert_eq!(error, 0);
assert_eq!(threading.len(), 6); // no removal on failure§Errors
If an element in replace_with is larger than the shaft count, returns index of first
out-of-bounds element
Sourcepub fn try_insert(
&mut self,
shaft: Shaft,
index: usize,
) -> Result<Result<(), Shaft>, usize>
pub fn try_insert( &mut self, shaft: Shaft, index: usize, ) -> Result<Result<(), Shaft>, usize>
Insert a thread at the given index, shifting later threads
§Errors
Returns the current length if index is greater than length
Sourcepub fn try_put(
&mut self,
index: usize,
shaft: Shaft,
) -> Result<Option<Shaft>, usize>
pub fn try_put( &mut self, index: usize, shaft: Shaft, ) -> Result<Option<Shaft>, usize>
Overwrite thread at given index. Returns replaced shaft, or none if inserting at the end
§Errors
Returns current length if index out of bounds
Sourcepub fn trim_shafts(&mut self) -> &Self
pub fn trim_shafts(&mut self) -> &Self
Shrinks the shaft count to the maximum shaft present in the threading. Returns the old shaft count if the count changed
Sourcepub fn used_shafts(&self) -> HashSet<u32>
pub fn used_shafts(&self) -> HashSet<u32>
Returns set of shafts used in the threading
§Examples
assert_eq!(HashSet::from([1,2,4]), Threading::new(4, vec![4, 1, 2, 1]).used_shafts());Sourcepub fn trim_and_squish_shafts(&mut self) -> &Self
pub fn trim_and_squish_shafts(&mut self) -> &Self
Removes any empty shafts, shifting threads down
Sourcepub fn flip_vertical(&mut self) -> &Self
pub fn flip_vertical(&mut self) -> &Self
Flips the threading vertically. On an 8 shaft threading, this means that shaft 1 becomes shaft 8 shaft 2 becomes shaft 7, and so on.