From 1217850149f2bf3fea08ea6dac0f1e46a799dd89 Mon Sep 17 00:00:00 2001 From: piaoliu <441594700@qq.com> Date: Mon, 15 Apr 2019 16:22:25 +0800 Subject: [PATCH] chore: add function to session id --- Cargo.toml | 2 +- src/lib.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b613542b..eda10d1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tentacle" -version = "0.2.0-alpha.2" +version = "0.2.0-alpha.3" license = "MIT" description = "Minimal implementation for a multiplexed p2p network framework." authors = ["piaoliu <441594700@qq.com>", "Nervos Core Dev "] diff --git a/src/lib.rs b/src/lib.rs index 7c344b01..57001b05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,12 +58,12 @@ pub struct ProtocolId(usize); impl ProtocolId { /// New a protocol id - pub fn new(id: usize) -> Self { + pub const fn new(id: usize) -> Self { ProtocolId(id) } /// Get inner value - pub fn value(self) -> usize { + pub const fn value(self) -> usize { self.0 } } @@ -84,6 +84,18 @@ impl From for ProtocolId { #[derive(Debug, Clone, Copy, Hash, Ord, PartialOrd, Eq, PartialEq, Default)] pub struct SessionId(usize); +impl SessionId { + /// New a session id + pub const fn new(id: usize) -> Self { + SessionId(id) + } + + /// Get inner value + pub const fn value(self) -> usize { + self.0 + } +} + impl fmt::Display for SessionId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "SessionId({})", self.0)