Skip to content

Commit

Permalink
Merge pull request #111 from nervosnetwork/add-function-to-sessionid
Browse files Browse the repository at this point in the history
chore: add function to session id
  • Loading branch information
driftluo authored Apr 15, 2019
2 parents 27129e3 + 1217850 commit 8e2120d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Nervos Core Dev <[email protected]>"]
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -84,6 +84,18 @@ impl From<usize> 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)
Expand Down

0 comments on commit 8e2120d

Please sign in to comment.