use super::packet::{PeerId, RawMixnodeIndex, MAX_MIXNODE_INDEX};
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct MixnodeIndex(RawMixnodeIndex);
impl MixnodeIndex {
pub fn get(self) -> RawMixnodeIndex {
self.0
}
}
impl TryFrom<usize> for MixnodeIndex {
type Error = ();
fn try_from(index: usize) -> Result<Self, Self::Error> {
if index <= MAX_MIXNODE_INDEX as usize {
Ok(Self(index as RawMixnodeIndex))
} else {
Err(())
}
}
}
impl TryFrom<RawMixnodeIndex> for MixnodeIndex {
type Error = ();
fn try_from(index: RawMixnodeIndex) -> Result<Self, Self::Error> {
(index as usize).try_into()
}
}
impl fmt::Display for MixnodeIndex {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(fmt)
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum Target {
MixnodeIndex(MixnodeIndex),
PeerId(PeerId),
}