Diffstat (limited to 'src/protocol/id.rs')
-rw-r--r--src/protocol/id.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/protocol/id.rs b/src/protocol/id.rs
index f1a1723..40aa2bc 100644
--- a/src/protocol/id.rs
+++ b/src/protocol/id.rs
@@ -2,13 +2,20 @@ use core::any::TypeId;
use super::Protocol;
+/// ID of a protocol.
+///
+/// An ID also includes the protocol's type name for easier debugging.
#[derive(Copy, Clone)]
pub struct ProtocolId {
+ /// Type ID of the protocol type.
id: fn() -> TypeId,
+
+ /// Name of the protocol type.
name: fn() -> &'static str,
}
impl ProtocolId {
+ /// Get the ID of a protocol.
pub const fn of<P: Protocol>() -> Self {
Self {
id: || core::any::TypeId::of::<P>(),
@@ -16,10 +23,16 @@ impl ProtocolId {
}
}
+ /// Type ID of the protocol.
+ ///
+ /// This is used for comparision.
fn id(&self) -> TypeId {
(self.id)()
}
+ /// Type name of the protocol.
+ ///
+ /// This is used for debugging purposes.
fn name(&self) -> &'static str {
(self.name)()
}
@@ -36,6 +49,7 @@ impl core::fmt::Debug for ProtocolId {
impl core::fmt::Display for ProtocolId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ // Just print the type name.
self.name().fmt(f)
}
}