Threading

Struct Threading 

Source
pub struct Threading { /* private fields */ }
Expand description

Threading in a weaving draft. 1 thread can only be on one shaft

Implementations§

Source§

impl Threading

Source

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

Source

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

Source

pub fn len(&self) -> usize

Number of threads in the threading

Source

pub fn is_empty(&self) -> bool

Is the threading empty

Source

pub fn threading(&self) -> &Vec<u32>

Get the raw threading

Source

pub fn push(&mut self, shaft: u32) -> Result<(), u32>

Add a new thread at the end of the threading

§Errors

Returns the shaft if greater than shaft count

Source

pub fn insert(&mut self, shaft: Shaft, index: usize) -> Result<(), Shaft>

Insert a thread at the given index, shifting later threads

§Panics

If index is greater than the length

§Errors

If shaft is greater than shaft_count

Source

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

Source

pub fn remove(&mut self, index: usize) -> Shaft

Remove the thread at the given index, returning it as a Shaft

§Panics

If index is out of bounds

Source

pub fn get(&self, index: usize) -> Option<&u32>

Get shaft at index

Source

pub fn put(&mut self, index: usize, shaft: Shaft) -> Shaft

Overwrite thread at given index, returns old thread value

§Panics

If index is out of bounds

Source

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

Source

pub fn max_shaft(&self) -> u32

Highest used shaft in threading

Source

pub fn set_shaft_count(&mut self, shaft_count: u32) -> Result<(), usize>

Non-destructively set shaft count

§Panics

If shaft_count is 0

§Errors

If shaft_count is less than max shaft used

Source

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

Source

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());
Source

pub fn trim_and_squish_shafts(&mut self) -> &Self

Removes any empty shafts, shifting threads down

Source

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.

Source

pub fn mirror(&mut self) -> &Self

Repeats the threading in reverse, does not repeat the final/center thread

§Examples
let mut threading = Threading::new(4, vec![1, 2, 3, 4]);
assert_eq!(threading.mirror().threading(), &vec![1, 2, 3, 4, 3, 2, 1]);
Source

pub fn reverse(&mut self) -> &Self

Reverse threading horizontally

Trait Implementations§

Source§

impl Add<&Threading> for Threading

Source§

type Output = Threading

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Threading) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Threading> for &Threading

Source§

type Output = Threading

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Threading) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for &Threading

Source§

type Output = Threading

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Threading

Source§

type Output = Threading

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Threading

Source§

fn clone(&self) -> Threading

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Threading

Source§

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

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

impl Default for Threading

Source§

fn default() -> Threading

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

impl<R> Index<R> for Threading
where R: SliceIndex<[u32]>,

Source§

type Output = <R as SliceIndex<[u32]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: R) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IntoIterator for Threading

Source§

type Item = u32

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Threading as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Threading

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Threading

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.