[−][src]Struct pair_macro::Triplet
Represents a pair consisting of the same-type values.
Fields
x: T
y: T
z: T
Implementations
impl<T> Triplet<T>
[src]
pub const fn new(x: T, y: T, z: T) -> Triplet<T>
[src]
Creates a new pair.
Examples
use pair_macro::Pair; let p = Pair::new(1, 2); assert_eq!(1, p.x); assert_eq!(2, p.y);
pub fn from_cloned(value: T) -> Triplet<T> where
T: Clone,
[src]
T: Clone,
Creates a new pair by cloning the specified value
.
Examples
use pair_macro::Pair; let p = Pair::from_cloned(vec![1, 2]); assert_eq!(vec![1, 2], p.x); assert_eq!(vec![1, 2], p.y);
pub const fn as_ref(&self) -> Triplet<&T>
[src]
Converts from &name<T>
to name<&T>
.
Examples
use pair_macro::Pair; let p = Pair::new(1, 2); let p = p.as_ref(); assert_eq!(&1, p.x); assert_eq!(&2, p.y);
pub fn as_mut(&mut self) -> Triplet<&mut T>
[src]
Converts from &mut name<T>
to name<&mut T>
.
Examples
use pair_macro::Pair; let mut p = Pair::new(1, 2); let q = p.as_mut(); *q.x = 3; *q.y = 4; assert_eq!(3, p.x); assert_eq!(4, p.y);
pub fn map<U, F>(self, f: F) -> Triplet<U> where
F: FnMut(T) -> U,
[src]
F: FnMut(T) -> U,
Applies an unary operation f
to each value.
Examples
use pair_macro::Pair; let p = Pair::new(1, 2).map(|value| value * 2); assert_eq!(2, p.x); assert_eq!(4, p.y);
pub fn map_in_place<F>(&mut self, f: F) -> &mut Triplet<T> where
F: FnMut(&mut T),
[src]
F: FnMut(&mut T),
Applies an unary operation f
in-place.
Returns
A mutable reference to itself.
Examples
use pair_macro::Pair; let mut p = Pair::new(2, 3); p.map_in_place(|value| *value += 1) .map_in_place(|value| *value *= 2); assert_eq!(6, p.x); assert_eq!(8, p.y);
pub fn map_entrywise<U, V, F>(self, rhs: Triplet<U>, f: F) -> Triplet<V> where
F: FnMut(T, U) -> V,
[src]
F: FnMut(T, U) -> V,
Applies a binary operation f
that takes two values, then produces another pair.
Examples
use pair_macro::Pair; let p = Pair::new(6, 8); let q = Pair::new(3, 2); let r = p.map_entrywise(q, |lhs, rhs| lhs / rhs); assert_eq!(2, r.x); assert_eq!(4, r.y);
pub fn map_entrywise_in_place<U, F>(
&mut self,
rhs: Triplet<U>,
f: F
) -> &mut Triplet<T> where
F: FnMut(&mut T, U),
[src]
&mut self,
rhs: Triplet<U>,
f: F
) -> &mut Triplet<T> where
F: FnMut(&mut T, U),
Applies a binary operation f
that takes two values, then stores the result in-place.
Returns
A mutable reference to itself.
Examples
use pair_macro::Pair; let mut p = Pair::new(2, 3); let q = Pair::new(4, 5); let r = Pair::new(6, 7); p.map_entrywise_in_place(q, |lhs, rhs| *lhs += rhs) .map_entrywise_in_place(r, |lhs, rhs| *lhs *= rhs); assert_eq!(36, p.x); assert_eq!(56, p.y);
pub fn fold<U, F>(self, init: U, f: F) -> U where
F: FnMut(U, T) -> U,
[src]
F: FnMut(U, T) -> U,
Applies a function f
to each values, then produces a single, final value.
Params
init
the initial value that the accumulator will have on the first call.f
accumulator that takes two arguments: current accumation and an value.
Examples
use pair_macro::Pair; let p = Pair::new(2, 3); let sum = p.fold(0, |accumulate, current| accumulate + current); let product = p.fold(1, |accumulate, current| accumulate * current); assert_eq!(5, sum); assert_eq!(6, product);
impl<T> Triplet<Option<T>>
[src]
pub fn into_option(self) -> Option<Triplet<T>>
[src]
Converts from name<Option<T>>
to Option<name<T>>
.
Returns
Some(pair)
if all values of the pair are Some(..)
, None
otherwise.
Examples
use pair_macro::Pair; let p = Pair::new(Some(1), Some(2)).into_option(); assert_eq!(Some(Pair::new(1, 2)), p); let q = Pair::new(Some(1), None).into_option(); assert!(q.is_none()); let r = Pair::<Option<i32>>::new(None, None).into_option(); assert!(r.is_none());
impl<T, E> Triplet<Result<T, E>>
[src]
pub fn into_result(self) -> Result<Triplet<T>, E>
[src]
Converts from name<Result<T, E>>
to Result<name<T>, E>
.
Returns
Ok(pair)
if all values of the pair are Ok(..)
.
Err(e)
if any value of the pair is Err(e)
, where e
is the value of the first Err(..)
value.
Examples
use pair_macro::Pair; use core::str::FromStr; let p = Pair::new("1", "2").map(i32::from_str).into_result(); assert_eq!(Ok(Pair::new(1, 2)), p); let q = Pair::new("1", "lamy").map(i32::from_str).into_result(); assert!(q.is_err()); let r = Pair::new("yukihana", "lamy").map(i32::from_str).into_result(); assert!(r.is_err());
Trait Implementations
impl<T, U> Add<Triplet<U>> for Triplet<T> where
T: Add<U>,
[src]
T: Add<U>,
type Output = Triplet<T::Output>
The resulting type after applying the +
operator.
pub fn add(self, rhs: Triplet<U>) -> Self::Output
[src]
impl<T> AddAssign<Triplet<T>> for Triplet<T> where
T: AddAssign,
[src]
T: AddAssign,
pub fn add_assign(&mut self, rhs: Self)
[src]
impl<T: Clone> Clone for Triplet<T>
[src]
pub fn clone(&self) -> Triplet<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Copy> Copy for Triplet<T>
[src]
impl<T: Debug> Debug for Triplet<T>
[src]
impl<T: Default> Default for Triplet<T>
[src]
impl<T> Display for Triplet<T> where
T: Display,
[src]
T: Display,
impl<T, U> Div<U> for Triplet<T> where
T: Div<U>,
U: Copy,
[src]
T: Div<U>,
U: Copy,
type Output = Triplet<T::Output>
The resulting type after applying the /
operator.
pub fn div(self, rhs: U) -> Self::Output
[src]
impl<T, U> DivAssign<U> for Triplet<T> where
T: DivAssign<U>,
U: Copy,
[src]
T: DivAssign<U>,
U: Copy,
pub fn div_assign(&mut self, rhs: U)
[src]
impl<T: Eq> Eq for Triplet<T>
[src]
impl<T: Hash> Hash for Triplet<T>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, U> Mul<U> for Triplet<T> where
T: Mul<U>,
U: Copy,
[src]
T: Mul<U>,
U: Copy,
type Output = Triplet<T::Output>
The resulting type after applying the *
operator.
pub fn mul(self, rhs: U) -> Self::Output
[src]
impl<T, U> MulAssign<U> for Triplet<T> where
T: MulAssign<U>,
U: Copy,
[src]
T: MulAssign<U>,
U: Copy,
pub fn mul_assign(&mut self, rhs: U)
[src]
impl<T> Neg for Triplet<T> where
T: Neg,
[src]
T: Neg,
type Output = Triplet<T::Output>
The resulting type after applying the -
operator.
pub fn neg(self) -> Self::Output
[src]
impl<T: PartialEq> PartialEq<Triplet<T>> for Triplet<T>
[src]
impl<T, U> Rem<U> for Triplet<T> where
T: Rem<U>,
U: Copy,
[src]
T: Rem<U>,
U: Copy,
type Output = Triplet<T::Output>
The resulting type after applying the %
operator.
pub fn rem(self, rhs: U) -> Self::Output
[src]
impl<T, U> RemAssign<U> for Triplet<T> where
T: RemAssign<U>,
U: Copy,
[src]
T: RemAssign<U>,
U: Copy,
pub fn rem_assign(&mut self, rhs: U)
[src]
impl<T> StructuralEq for Triplet<T>
[src]
impl<T> StructuralPartialEq for Triplet<T>
[src]
impl<T, U> Sub<Triplet<U>> for Triplet<T> where
T: Sub<U>,
[src]
T: Sub<U>,
type Output = Triplet<T::Output>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Triplet<U>) -> Self::Output
[src]
impl<T> SubAssign<Triplet<T>> for Triplet<T> where
T: SubAssign,
[src]
T: SubAssign,
pub fn sub_assign(&mut self, rhs: Self)
[src]
Auto Trait Implementations
impl<T> Send for Triplet<T> where
T: Send,
T: Send,
impl<T> Sync for Triplet<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Triplet<T> where
T: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,