wasm_peers_protocol/
lib.rs1#![deny(missing_docs)]
7
8use serde::{Deserialize, Serialize};
9use std::fmt::{Display, Formatter};
10use std::ops::Deref;
11use std::str::FromStr;
12
13pub mod many_to_many;
14pub mod one_to_many;
15pub mod one_to_one;
16
17#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
20pub struct SessionId(String);
21
22impl SessionId {
23 pub fn new(inner: String) -> Self {
25 SessionId(inner)
26 }
27
28 pub fn as_str(&self) -> &str {
30 &self.0
31 }
32 pub fn into_inner(self) -> String {
34 self.0
35 }
36}
37
38impl FromStr for SessionId {
39 type Err = Box<dyn std::error::Error>;
40
41 fn from_str(s: &str) -> Result<Self, Self::Err> {
42 Ok(SessionId(s.to_string()))
43 }
44}
45
46impl Display for SessionId {
47 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
48 write!(f, "{}", self.0)
49 }
50}
51
52#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
55pub struct UserId(usize);
56
57impl UserId {
58 pub fn new(inner: usize) -> Self {
60 UserId(inner)
61 }
62
63 pub fn into_inner(self) -> usize {
65 self.0
66 }
67}
68
69impl From<usize> for UserId {
70 fn from(val: usize) -> Self {
71 UserId(val)
72 }
73}
74
75impl Display for UserId {
76 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
77 write!(f, "{}", self.0)
78 }
79}
80
81impl Deref for UserId {
82 type Target = usize;
83
84 fn deref(&self) -> &Self::Target {
85 &self.0
86 }
87}
88
89pub type IsHost = bool;