#[repr(transparent)]pub struct NodeId(_);
Expand description
A node ID
This is an integer referring to a row of a NodeTable
.
The underlying type is tsk_id_t
.
Examples
These examples illustrate using this type as something “integer-like”.
use tskit::NodeId;
use tskit::bindings::tsk_id_t;
// The default value is null:
assert_eq!(tskit::NodeId::default(), tskit::NodeId::NULL);
let x: tsk_id_t = 1;
let y: NodeId = NodeId::from(x);
assert_eq!(x, y);
assert_eq!(y, x);
assert!(y < x + 1);
assert!(y <= x);
assert!(x + 1 > y);
assert!(x + 1 >= y);
let z: NodeId = NodeId::from(x);
assert_eq!(y, z);
It is also possible to write functions accepting both the NodeId
and tsk_id_t
:
use tskit::NodeId;
use tskit::bindings::tsk_id_t;
fn interesting<N: Into<NodeId>>(x: N) -> NodeId {
x.into()
}
let x: tsk_id_t = 0;
assert_eq!(interesting(x), x);
let x: NodeId = NodeId::from(0);
assert_eq!(interesting(x), x);
The types also implement Display
:
use tskit::NodeId;
let n = NodeId::from(11);
assert_eq!(format!("{}", n), "11".to_string());
// Debug output contains type info
assert_eq!(format!("{:?}", n), "NodeId(11)".to_string());
let n = NodeId::from(NodeId::NULL);
assert_eq!(format!("{}", n), "NULL");
assert_eq!(format!("{:?}", n), "NodeId(-1)");
Implementations§
Trait Implementations§
source§impl Ord for NodeId
impl Ord for NodeId
source§impl PartialEq<NodeId> for NodeId
impl PartialEq<NodeId> for NodeId
source§impl PartialEq<NodeId> for SizeType
impl PartialEq<NodeId> for SizeType
source§impl PartialEq<NodeId> for tsk_id_t
impl PartialEq<NodeId> for tsk_id_t
source§impl PartialEq<SizeType> for NodeId
impl PartialEq<SizeType> for NodeId
source§impl PartialEq<i32> for NodeId
impl PartialEq<i32> for NodeId
source§impl PartialOrd<NodeId> for NodeId
impl PartialOrd<NodeId> for NodeId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<NodeId> for SizeType
impl PartialOrd<NodeId> for SizeType
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<NodeId> for tsk_id_t
impl PartialOrd<NodeId> for tsk_id_t
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<SizeType> for NodeId
impl PartialOrd<SizeType> for NodeId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<i32> for NodeId
impl PartialOrd<i32> for NodeId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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