Skip to main content

use_molecule/
atom_index.rs

1use std::fmt;
2
3/// A zero-based atom index into a molecule's explicit atom list.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub struct AtomIndex(usize);
6
7impl AtomIndex {
8    /// Creates an atom index.
9    #[must_use]
10    pub const fn new(index: usize) -> Self {
11        Self(index)
12    }
13
14    /// Returns the zero-based index value.
15    #[must_use]
16    pub const fn get(self) -> usize {
17        self.0
18    }
19}
20
21impl From<usize> for AtomIndex {
22    fn from(value: usize) -> Self {
23        Self::new(value)
24    }
25}
26
27impl fmt::Display for AtomIndex {
28    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
29        write!(formatter, "{}", self.0)
30    }
31}
32
33/// A count of explicit atoms in a molecule.
34#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
35pub struct AtomCount(usize);
36
37impl AtomCount {
38    /// Creates an atom count.
39    #[must_use]
40    pub const fn new(count: usize) -> Self {
41        Self(count)
42    }
43
44    /// Returns the count value.
45    #[must_use]
46    pub const fn get(self) -> usize {
47        self.0
48    }
49
50    /// Returns `true` when the count is zero.
51    #[must_use]
52    pub const fn is_zero(self) -> bool {
53        self.0 == 0
54    }
55}
56
57impl From<usize> for AtomCount {
58    fn from(value: usize) -> Self {
59        Self::new(value)
60    }
61}
62
63impl fmt::Display for AtomCount {
64    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
65        write!(formatter, "{}", self.0)
66    }
67}