1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
use std::fmt; #[cfg(feature = "tiny-ids")] mod index_type { pub type NeuronIndex = u8; pub type EdgeIndex = u16; } #[cfg(feature = "small-ids")] mod index_type { pub type NeuronIndex = u16; pub type EdgeIndex = u32; } #[cfg(not(any(feature = "tiny-ids", feature = "small-ids")))] mod index_type { pub type NeuronIndex = u32; pub type EdgeIndex = u32; } use index_type::*; #[derive(Deserialize, Serialize, Debug, Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NeuronId(NeuronIndex); impl NeuronId { pub const MIN: usize = 0; pub const MAX: usize = NeuronIndex::MAX as usize; pub fn new(index: usize) -> Self { if index > Self::MAX as usize { panic!("NeuronId too small, layer has more then {} neurons", Self::MAX); } Self(index as NeuronIndex) } pub fn index(&self) -> usize { self.0 as usize } } impl fmt::Display for NeuronId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } #[derive(Deserialize, Serialize, Debug, Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct EdgeId(EdgeIndex); impl EdgeId { pub const MIN: usize = 0; pub const MAX: usize = EdgeIndex::MAX as usize; pub fn new(index: usize) -> Self { if index > Self::MAX as usize { panic!("EdgeId too small, layer has more then {} edges", Self::MAX); } Self(index as EdgeIndex) } pub fn index(&self) -> usize { self.0 as usize } } impl fmt::Display for EdgeId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } }