pub struct NodeId(/* private fields */);
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 PartialOrd<NodeId> for SizeType
impl PartialOrd<NodeId> for SizeType
Source§impl PartialOrd<NodeId> for tsk_id_t
impl PartialOrd<NodeId> for tsk_id_t
Source§impl PartialOrd<SizeType> for NodeId
impl PartialOrd<SizeType> for NodeId
Source§impl PartialOrd<i32> for NodeId
impl PartialOrd<i32> for NodeId
Source§impl PartialOrd for NodeId
impl PartialOrd for NodeId
impl Copy for NodeId
impl Eq for NodeId
impl StructuralPartialEq for NodeId
Auto Trait Implementations§
impl Freeze for NodeId
impl RefUnwindSafe for NodeId
impl Send for NodeId
impl Sync for NodeId
impl Unpin for NodeId
impl UnwindSafe for NodeId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more