Triplet

Struct Triplet 

Source
pub struct Triplet<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}
Expand description

Represents a pair consisting of 3 values.

Fields§

§x: T§y: T§z: T

Implementations§

Source§

impl<T> Triplet<T>

Source

pub const fn new(x: T, y: T, z: T) -> Triplet<T>

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);
Examples found in repository?
examples/demo.rs (line 47)
26fn main() {
27    println!("dynpick-force-torque-sensor demo started.");
28    println!("Make sure that the sensor is connected to the computer.");
29    println!("Make sure setting udev rule. See examples/setup_udev_rule.sh in detail.");
30
31    // Search USB-connected dynpick sensor.
32    let path = match search_usb_sensor_path() {
33        Ok(Some(path)) => path,
34        Ok(None) => {
35            println!("No dynpick sensor is connected.");
36            return;
37        }
38        Err(e) => {
39            println!("{}", e);
40            return;
41        }
42    };
43    println!("Found a sensor. Path: {}", path);
44
45    // Specify the sensitivity manually.
46    let sensitivity = {
47        let force = Triplet::new(24.9, 24.6, 24.5);
48        let torque = Triplet::new(1664.7, 1639.7, 1638.0);
49        Sensitivity::new(force, torque)
50    };
51
52    // Connect the found sensor.
53    let sensor = DynpickSensorBuilder::open(path)
54        .map(|b| b.set_sensitivity_manually(sensitivity))
55        .and_then(|b| b.build());
56    let mut sensor = match sensor {
57        Ok(s) => s,
58        Err(e) => {
59            println!("{}", e);
60            return;
61        }
62    };
63    println!("Successfully opened the sensor.");
64
65    // Correct zero-point
66    match sensor.zeroed_next() {
67        Ok(_) => println!("Offset the sensor."),
68        Err(e) => {
69            println!("An error occurred during offset: {}", e);
70            return;
71        }
72    }
73
74    // Repeatedly receive wrenches from the sensor.
75    let measurement_count = 1000;
76    for i in 0..measurement_count {
77        std::thread::sleep(sensor.inner_port().timeout());
78
79        match sensor.update() {
80            Ok(w) => println!("[{}/{}] {:?}", i + 1, measurement_count, w),
81            Err(e) => println!("[{}/{}] {}", i + 1, measurement_count, e),
82        }
83    }
84
85    // Info
86    println!("Product info: {:?}", sensor.receive_product_info());
87
88    println!("dynpick-force-torque-sensor demo finished.");
89}
Source

pub fn from_cloned(value: T) -> Triplet<T>
where T: Clone,

Creates a new pair by cloning the specified value.

§Examples
use pair_macro::Pair;

let p = Pair::from_cloned([1, 2]);
assert_eq!([1, 2], p.x);
assert_eq!([1, 2], p.y);
Source

pub const fn as_ref(&self) -> Triplet<&T>

Converts from &name<T> to name<&T>.

§Examples
use pair_macro::Pair;

let p = Pair::new(1, 2);
let q = p.as_ref();

assert_eq!(Pair::new(&1, &2), q);
Source

pub fn as_mut(&mut self) -> Triplet<&mut T>

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

assert_eq!(Pair::new(&mut 1, &mut 2), q);
Source

pub fn map<U, F>(self, f: F) -> Triplet<U>
where 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);
Source

pub fn map_in_place<F>(&mut self, f: F) -> &mut Triplet<T>
where 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);
Source

pub fn map_entrywise<U, V, F>(self, rhs: Triplet<U>, f: F) -> Triplet<V>
where 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);
Source

pub fn map_entrywise_in_place<U, F>( &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);
Source

pub fn fold<U, F>(self, init: U, f: F) -> U
where F: FnMut(U, T) -> U,

👎Deprecated since 0.1.3: Use into_iter().fold(init, f) instead

Applies a function f to each values, then produces a single, final value.

§Params
  1. init the initial value that the accumulator will have on the first call.
  2. 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);
Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator that yields references of each value.

§Examples
use pair_macro::Pair;

let p = Pair::new(2, 3);
let mut iter = p.iter();
assert_eq!(Some(&2), iter.next());
assert_eq!(Some(&3), iter.next());
assert!(iter.next().is_none());
Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Returns an iterator that yields mutable references of each value.

§Examples
use pair_macro::Pair;

let mut p = Pair::new(2, 3);
let mut iter = p.iter_mut();
assert_eq!(Some(&mut 2), iter.next());
assert_eq!(Some(&mut 3), iter.next());
assert!(iter.next().is_none());
Source

pub fn into_iter(self) -> impl Iterator<Item = T>

Consuming this pair, returns an iterator that yields each value.

§Examples
use pair_macro::Pair;

let p = Pair::new(2, 3);
let mut iter = p.into_iter();
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
assert!(iter.next().is_none());
Source§

impl<T> Triplet<T>
where T: Deref,

Source

pub fn as_deref(&self) -> Triplet<&<T as Deref>::Target>

Converts from $name<T> or &$name<T> to $name<&T::Target>.

Leaves the original pair in-place, creating a new one with a reference to the original one, additionally coercing the contents via Deref.

§Examples
use pair_macro::Pair;

let p = Pair::new(2, 3);
let q = p.as_ref(); // Pair<&i32>
let r = q.as_deref(); // Pair<&i32>, using trait implementation Deref<Target=i32> for &i32
assert_eq!(Pair::new(&2, &3), r);
Source§

impl<T> Triplet<T>
where T: DerefMut,

Source

pub fn as_deref_mut(&mut self) -> Triplet<&mut <T as Deref>::Target>

Converts from $name<T> or &mut $name<T> to $name<&mut T::Target>.

Leaves the original pair in-place, creating a new one with a mutable reference to the original one, additionally coercing the contents via DerefMut.

§Examples
use pair_macro::Pair;

let mut p = Pair::new(2, 3);
let mut q = p.as_mut(); // Pair<&mut i32>
let r = q.as_deref_mut(); // Pair<&mut i32>, using trait implementation DerefMut<Target=i32> for &mut i32
assert_eq!(Pair::new(&mut 2, &mut 3), r);
Source§

impl<T> Triplet<&T>
where T: Clone,

Source

pub fn cloned(self) -> Triplet<T>

Maps Pair<&T> to Pair<T> by cloning each value.

§Examples
use pair_macro::Pair;

let p = Pair::new(2, 3); // Pair<i32>
let q = p.as_ref(); // Pair<&i32>
assert_eq!(p, q.cloned());
Source§

impl<T> Triplet<&mut T>
where T: Clone,

Source

pub fn cloned(self) -> Triplet<T>

Maps Pair<&mut T> to Pair<T> by cloning each value.

§Examples
use pair_macro::Pair;

let mut p = Pair::new(2, 3); // Pair<i32>
let q = p.as_mut(); // Pair<&mut i32>
let cloned = q.cloned();
assert_eq!(p, cloned);
Source§

impl<T> Triplet<&T>
where T: Copy,

Source

pub fn copied(self) -> Triplet<T>

Maps Pair<&T> to Pair<T> by copying each value.

§Examples
use pair_macro::Pair;

let p = Pair::new(2, 3); // Pair<i32>
let q = p.as_ref(); // Pair<&i32>
assert_eq!(p, q.copied());
Source§

impl<T> Triplet<&mut T>
where T: Copy,

Source

pub fn copied(self) -> Triplet<T>

Maps Pair<&mut T> to Pair<T> by copying each value.

§Examples
use pair_macro::Pair;

let mut p = Pair::new(2, 3); // Pair<i32>
let q = p.as_mut(); // Pair<&mut i32>
let copied = q.copied();
assert_eq!(p, copied);
Source§

impl<T> Triplet<Option<T>>

Source

pub fn into_option(self) -> Option<Triplet<T>>

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

impl<T, E> Triplet<Result<T, E>>

Source

pub fn into_result(self) -> Result<Triplet<T>, E>

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§

Source§

impl<T, U> Add<Triplet<U>> for Triplet<T>
where T: Add<U>,

Source§

type Output = Triplet<<T as Add<U>>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Triplet<U>) -> <Triplet<T> as Add<Triplet<U>>>::Output

Performs the + operation. Read more
Source§

impl<T> AddAssign for Triplet<T>
where T: AddAssign,

Source§

fn add_assign(&mut self, rhs: Triplet<T>)

Performs the += operation. Read more
Source§

impl<T> Clone for Triplet<T>
where T: Clone,

Source§

fn clone(&self) -> Triplet<T>

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<T> Debug for Triplet<T>
where T: Debug,

Source§

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

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

impl<T> Default for Triplet<T>
where T: Default,

Source§

fn default() -> Triplet<T>

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

impl<T> Display for Triplet<T>
where T: Display,

Source§

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

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

impl<T, U> Div<U> for Triplet<T>
where T: Div<U>, U: Copy,

Source§

type Output = Triplet<<T as Div<U>>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: U) -> <Triplet<T> as Div<U>>::Output

Performs the / operation. Read more
Source§

impl<T, U> DivAssign<U> for Triplet<T>
where T: DivAssign<U>, U: Copy,

Source§

fn div_assign(&mut self, rhs: U)

Performs the /= operation. Read more
Source§

impl<T> Hash for Triplet<T>
where T: Hash,

Source§

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

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, U> Mul<U> for Triplet<T>
where T: Mul<U>, U: Copy,

Source§

type Output = Triplet<<T as Mul<U>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: U) -> <Triplet<T> as Mul<U>>::Output

Performs the * operation. Read more
Source§

impl<T, U> MulAssign<U> for Triplet<T>
where T: MulAssign<U>, U: Copy,

Source§

fn mul_assign(&mut self, rhs: U)

Performs the *= operation. Read more
Source§

impl<T> Neg for Triplet<T>
where T: Neg,

Source§

type Output = Triplet<<T as Neg>::Output>

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Triplet<T> as Neg>::Output

Performs the unary - operation. Read more
Source§

impl<T> PartialEq for Triplet<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Triplet<T>) -> 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<T, U> Rem<U> for Triplet<T>
where T: Rem<U>, U: Copy,

Source§

type Output = Triplet<<T as Rem<U>>::Output>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: U) -> <Triplet<T> as Rem<U>>::Output

Performs the % operation. Read more
Source§

impl<T, U> RemAssign<U> for Triplet<T>
where T: RemAssign<U>, U: Copy,

Source§

fn rem_assign(&mut self, rhs: U)

Performs the %= operation. Read more
Source§

impl<T, U> Sub<Triplet<U>> for Triplet<T>
where T: Sub<U>,

Source§

type Output = Triplet<<T as Sub<U>>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Triplet<U>) -> <Triplet<T> as Sub<Triplet<U>>>::Output

Performs the - operation. Read more
Source§

impl<T> SubAssign for Triplet<T>
where T: SubAssign,

Source§

fn sub_assign(&mut self, rhs: Triplet<T>)

Performs the -= operation. Read more
Source§

impl<T> Copy for Triplet<T>
where T: Copy,

Source§

impl<T> Eq for Triplet<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Triplet<T>

Auto Trait Implementations§

§

impl<T> Freeze for Triplet<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Triplet<T>
where T: RefUnwindSafe,

§

impl<T> Send for Triplet<T>
where T: Send,

§

impl<T> Sync for Triplet<T>
where T: Sync,

§

impl<T> Unpin for Triplet<T>
where T: Unpin,

§

impl<T> UnwindSafe for Triplet<T>
where T: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.