Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: i1i1 <vanyarybin1@live.ru>
- Loading branch information
Showing
4 changed files
with
240 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{ | ||
fmt::{self, Debug, Display}, | ||
hash::Hash, | ||
sync::atomic::{AtomicUsize, Ordering}, | ||
}; | ||
|
||
static ACTOR_ID_COUNTER: AtomicUsize = AtomicUsize::new(0); | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct ActorId { | ||
pub name: Option<&'static str>, | ||
pub id: usize, | ||
} | ||
|
||
impl ActorId { | ||
pub fn new(name: Option<&'static str>) -> Self { | ||
Self { | ||
name, | ||
id: ACTOR_ID_COUNTER.fetch_add(1, Ordering::SeqCst), | ||
} | ||
} | ||
} | ||
|
||
impl Display for ActorId { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
if let Some(name) = &self.name { | ||
write!(f, "{}:{}", name, self.id) | ||
} else { | ||
write!(f, "<unknown>:{}", self.id) | ||
} | ||
} | ||
} | ||
|
||
impl Debug for ActorId { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
Display::fmt(&self, f) | ||
} | ||
} | ||
|
||
impl Hash for ActorId { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.id.hash(state) | ||
} | ||
} | ||
|
||
impl PartialEq for ActorId { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.id == other.id | ||
} | ||
} | ||
impl Eq for ActorId {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.