Struct new_units::Unit

source ·
#[repr(transparent)]
pub struct Unit<T, Marker>(pub T, _);
Expand description

Add a marker to another type, eg Unit<Point3, LastPosition>.

Units try to be as transparent as possible: they deref to T, and the various operators forward to it.

Tuple Fields§

§0: T

Implementations§

source§

impl<T, M> Unit<T, M>

source

pub fn map<R>(self, f: impl FnOnce(T) -> R) -> Unit<R, M>

Change the contained value. Note that Unit also implements Deref, DerefMut, etc; or you can use self.0.

source

pub fn with_unit<N>(self, _n: N) -> Unit<T, N>

Change the unit.

Example
use new_units::*;
struct Position;
struct LastPosition;
let position = (0, 0).of(Position);
// (And then some stuff happens...)
let previous_position = position.with_unit(LastPosition);
source§

impl<T> Unit<T, ()>

source

pub const fn new<M>(t: T) -> Unit<T, M>

source

pub const fn index<M>(t: T) -> Unit<T, [M; 0]>

Constructs an index. You can use this to prevent using an index on the wrong value.

See OfUnit::over for a more pleasant API.

Example
let data1 = vec![0];
struct Marked;
let data2 = Unit::new::<Marked>(data1.clone());
assert_eq!(
    data1[0],
    data2[Unit::index::<Marked>(0usize)],
);
source§

impl<M> Unit<usize, M>

source

pub fn shrink<U: IntoIndex>(self) -> Unit<U, M>

Reduce the size. Panics if too large.

See Also

IntoIndex

Trait Implementations§

source§

impl<T, M> Add<T> for Unit<T, M>where T: Add<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T, M> Add<Unit<T, M>> for Unit<T, M>where T: Add<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T, M> AddAssign<T> for Unit<T, M>where T: AddAssign,

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl<T, M> AddAssign<Unit<T, M>> for Unit<T, M>where T: AddAssign,

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<T, M> BitAnd<T> for Unit<T, M>where T: BitAnd<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: T) -> Self::Output

Performs the & operation. Read more
source§

impl<T, M> BitAnd<Unit<T, M>> for Unit<T, M>where T: BitAnd<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the & operator.
source§

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

Performs the & operation. Read more
source§

impl<T, M> BitAndAssign<T> for Unit<T, M>where T: BitAndAssign,

source§

fn bitand_assign(&mut self, rhs: T)

Performs the &= operation. Read more
source§

impl<T, M> BitAndAssign<Unit<T, M>> for Unit<T, M>where T: BitAndAssign,

source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
source§

impl<T, M> BitOr<T> for Unit<T, M>where T: BitOr<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: T) -> Self::Output

Performs the | operation. Read more
source§

impl<T, M> BitOr<Unit<T, M>> for Unit<T, M>where T: BitOr<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the | operator.
source§

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

Performs the | operation. Read more
source§

impl<T, M> BitOrAssign<T> for Unit<T, M>where T: BitOrAssign,

source§

fn bitor_assign(&mut self, rhs: T)

Performs the |= operation. Read more
source§

impl<T, M> BitOrAssign<Unit<T, M>> for Unit<T, M>where T: BitOrAssign,

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

impl<T, M> BitXor<T> for Unit<T, M>where T: BitXor<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: T) -> Self::Output

Performs the ^ operation. Read more
source§

impl<T, M> BitXor<Unit<T, M>> for Unit<T, M>where T: BitXor<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the ^ operator.
source§

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

Performs the ^ operation. Read more
source§

impl<T, M> BitXorAssign<T> for Unit<T, M>where T: BitXorAssign,

source§

fn bitxor_assign(&mut self, rhs: T)

Performs the ^= operation. Read more
source§

impl<T, M> BitXorAssign<Unit<T, M>> for Unit<T, M>where T: BitXorAssign,

source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
source§

impl<T: Clone, M> Clone for Unit<T, M>

source§

fn clone(&self) -> Self

Returns a copy 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<T: Debug, M> Debug for Unit<T, M>

source§

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

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

impl<T: Default, M> Default for Unit<T, M>

source§

fn default() -> Self

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

impl<T, M> Deref for Unit<T, M>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T, M> DerefMut for Unit<T, M>

source§

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

Mutably dereferences the value.
source§

impl<T, M> Div<T> for Unit<T, M>where T: Div<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T, M> Div<Unit<T, M>> for Unit<T, M>where T: Div<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T, M> DivAssign<T> for Unit<T, M>where T: DivAssign,

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl<T, M> DivAssign<Unit<T, M>> for Unit<T, M>where T: DivAssign,

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl<T, Marker> From<T> for Unit<T, Marker>

source§

fn from(t: T) -> Self

Converts to this type from the input type.
source§

impl<T: Hash, M> Hash for Unit<T, M>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, M, I> Index<Unit<I, [M; 0]>> for Unit<T, M>where T: Index<usize>, I: IntoIndex,

§

type Output = <T as Index<usize>>::Output

The returned type after indexing.
source§

fn index(&self, index: Unit<I, [M; 0]>) -> &Self::Output

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

impl<T, M, I> IndexMut<Unit<I, [M; 0]>> for Unit<T, M>where T: IndexMut<usize>, I: IntoIndex,

source§

fn index_mut(&mut self, index: Unit<I, [M; 0]>) -> &mut Self::Output

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

impl<T, M> Mul<T> for Unit<T, M>where T: Mul<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T, M> Mul<Unit<T, M>> for Unit<T, M>where T: Mul<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T, M> MulAssign<T> for Unit<T, M>where T: MulAssign,

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl<T, M> MulAssign<Unit<T, M>> for Unit<T, M>where T: MulAssign,

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl<T, M> PartialEq<T> for Unit<T, M>where T: PartialEq,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, M> PartialEq<Unit<T, M>> for Unit<T, M>where T: PartialEq,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, M> PartialOrd<T> for Unit<T, M>where T: PartialOrd,

source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, M> PartialOrd<Unit<T, M>> for Unit<T, M>where T: PartialOrd,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, M> Rem<T> for Unit<T, M>where T: Rem<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: T) -> Self::Output

Performs the % operation. Read more
source§

impl<T, M> Rem<Unit<T, M>> for Unit<T, M>where T: Rem<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl<T, M> RemAssign<T> for Unit<T, M>where T: RemAssign,

source§

fn rem_assign(&mut self, rhs: T)

Performs the %= operation. Read more
source§

impl<T, M> RemAssign<Unit<T, M>> for Unit<T, M>where T: RemAssign,

source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
source§

impl<T, M> Shl<T> for Unit<T, M>where T: Shl<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the << operator.
source§

fn shl(self, rhs: T) -> Self::Output

Performs the << operation. Read more
source§

impl<T, M> Shl<Unit<T, M>> for Unit<T, M>where T: Shl<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the << operator.
source§

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

Performs the << operation. Read more
source§

impl<T, M> ShlAssign<T> for Unit<T, M>where T: ShlAssign,

source§

fn shl_assign(&mut self, rhs: T)

Performs the <<= operation. Read more
source§

impl<T, M> ShlAssign<Unit<T, M>> for Unit<T, M>where T: ShlAssign,

source§

fn shl_assign(&mut self, rhs: Self)

Performs the <<= operation. Read more
source§

impl<T, M> Shr<T> for Unit<T, M>where T: Shr<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: T) -> Self::Output

Performs the >> operation. Read more
source§

impl<T, M> Shr<Unit<T, M>> for Unit<T, M>where T: Shr<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the >> operator.
source§

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

Performs the >> operation. Read more
source§

impl<T, M> ShrAssign<T> for Unit<T, M>where T: ShrAssign,

source§

fn shr_assign(&mut self, rhs: T)

Performs the >>= operation. Read more
source§

impl<T, M> ShrAssign<Unit<T, M>> for Unit<T, M>where T: ShrAssign,

source§

fn shr_assign(&mut self, rhs: Self)

Performs the >>= operation. Read more
source§

impl<T, M> Sub<T> for Unit<T, M>where T: Sub<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
source§

impl<T, M> Sub<Unit<T, M>> for Unit<T, M>where T: Sub<T, Output = T>,

§

type Output = Unit<T, M>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T, M> SubAssign<T> for Unit<T, M>where T: SubAssign,

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl<T, M> SubAssign<Unit<T, M>> for Unit<T, M>where T: SubAssign,

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<T: Copy, M> Copy for Unit<T, M>

source§

impl<T: Eq, M> Eq for Unit<T, M>

Auto Trait Implementations§

§

impl<T, Marker> RefUnwindSafe for Unit<T, Marker>where Marker: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, Marker> Send for Unit<T, Marker>where Marker: Send, T: Send,

§

impl<T, Marker> Sync for Unit<T, Marker>where Marker: Sync, T: Sync,

§

impl<T, Marker> Unpin for Unit<T, Marker>where Marker: Unpin, T: Unpin,

§

impl<T, Marker> UnwindSafe for Unit<T, Marker>where Marker: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

const: unstable · source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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<X> OfUnit for X

source§

fn of<M>(self, _m: M) -> Unit<Self, M>

Ascribe a unit onto this value. Read more
source§

fn over<M>(self, _m: M) -> Unit<Self, [M; 0]>

Let this value be an index into Ms. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.