Struct truck_topology::Vertex[][src]

pub struct Vertex<P> { /* fields omitted */ }

Vertex, the minimum topological unit.

The constructor Vertex::new() creates a different vertex each time. These vertices are uniquely identified by their id.

let v0 = Vertex::new(()); // one vertex
let v1 = Vertex::new(()); // another vertex
assert_ne!(v0, v1); // two vertices are different

Implementations

impl<P> Vertex<P>[src]

pub fn new(point: P) -> Vertex<P>[src]

constructor

Examples

use truck_topology::*;
let v0 = Vertex::new(()); // a vertex whose geometry is the empty tuple.
let v1 = Vertex::new(()); // another vertex
let v2 = v0.clone(); // a cloned vertex
assert_ne!(v0, v1);
assert_eq!(v0, v2);

pub fn news(points: &[P]) -> Vec<Vertex<P>>

Notable traits for Vec<u8, Global>

impl Write for Vec<u8, Global>
where
    P: Copy
[src]

Creates len distinct vertices and return them by vector.

Examples

use truck_topology::Vertex;
let v = Vertex::news(&[(), (), ()]);
assert_eq!(v.len(), 3);
assert_ne!(v[0], v[2]);

pub fn try_lock_point(&self) -> TryLockResult<MutexGuard<'_, P>>[src]

Tries to lock the mutex of the contained point. The thread will not blocked.

Examples

use truck_topology::*;
let v0 = Vertex::new(0);
let v1 = v0.clone();

// Two vertices have the same content.
assert_eq!(*v0.try_lock_point().unwrap(), 0);
assert_eq!(*v1.try_lock_point().unwrap(), 0);

{
    let mut point = v0.try_lock_point().unwrap();
    *point = 1;
}
// The contents of two vertices are synchronized.
assert_eq!(*v0.try_lock_point().unwrap(), 1);
assert_eq!(*v1.try_lock_point().unwrap(), 1);

// The thread is not blocked even if the point is already locked.
let lock = v0.try_lock_point();
assert!(v1.try_lock_point().is_err());    

pub fn lock_point(&self) -> LockResult<MutexGuard<'_, P>>[src]

Acquires the mutex of the contained point, blocking the current thread until it is able to do so.

Examples

use truck_topology::*;
let v0 = Vertex::new(0);
let v1 = v0.clone();

// Two vertices have the same content.
assert_eq!(*v0.lock_point().unwrap(), 0);
assert_eq!(*v1.lock_point().unwrap(), 0);

{
    let mut point = v0.lock_point().unwrap();
    *point = 1;
}
// The contents of two vertices are synchronized.
assert_eq!(*v0.lock_point().unwrap(), 1);
assert_eq!(*v1.lock_point().unwrap(), 1);

// Check the behavior of `lock`.
std::thread::spawn(move || {
    *v0.lock_point().unwrap() = 2;
}).join().expect("thread::spawn failed");
assert_eq!(*v1.lock_point().unwrap(), 2);    

pub fn id(&self) -> VertexID<P>[src]

Returns the id of the vertex.

Trait Implementations

impl<P> Clone for Vertex<P>[src]

impl<P: Debug> Debug for Vertex<P>[src]

impl<P> Eq for Vertex<P>[src]

impl<P> Hash for Vertex<P>[src]

impl<P> PartialEq<Vertex<P>> for Vertex<P>[src]

Auto Trait Implementations

impl<P> RefUnwindSafe for Vertex<P>[src]

impl<P> Send for Vertex<P> where
    P: Send
[src]

impl<P> Sync for Vertex<P> where
    P: Send
[src]

impl<P> Unpin for Vertex<P>[src]

impl<P> UnwindSafe for Vertex<P>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.