erosbag_core/
identifier.rs

1use std::fmt;
2
3/// Dedicated type for an identifier of a topic.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
5pub struct TopicId(i32);
6
7impl fmt::Display for TopicId {
8    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9        write!(f, "{}", self.0)
10    }
11}
12
13impl From<TopicId> for i32 {
14    fn from(item: TopicId) -> Self {
15        item.0
16    }
17}
18
19impl From<i32> for TopicId {
20    fn from(item: i32) -> Self {
21        Self(item)
22    }
23}
24
25/// Dedicated type for an identifier of a channel.
26#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
27pub struct FileName(String);
28
29impl fmt::Display for FileName {
30    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31        write!(f, "{}", self.0)
32    }
33}
34
35impl From<FileName> for String {
36    fn from(item: FileName) -> Self {
37        item.0
38    }
39}
40
41impl From<String> for FileName {
42    fn from(item: String) -> Self {
43        Self(item)
44    }
45}
46
47impl From<&str> for FileName {
48    fn from(item: &str) -> Self {
49        Self(item.to_string())
50    }
51}
52
53/// Dedicated type for an identifier of a chunk.
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
55pub struct ChunkId(usize);
56
57impl fmt::Display for ChunkId {
58    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59        write!(f, "{}", self.0)
60    }
61}
62
63impl From<ChunkId> for usize {
64    fn from(item: ChunkId) -> Self {
65        item.0
66    }
67}
68
69impl From<usize> for ChunkId {
70    fn from(item: usize) -> Self {
71        Self(item)
72    }
73}
74
75/// Dedicated type for an identifier of a channel.
76#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
77pub struct ChannelTopic(String);
78
79impl fmt::Display for ChannelTopic {
80    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81        write!(f, "{}", self.0)
82    }
83}
84
85impl From<ChannelTopic> for String {
86    fn from(item: ChannelTopic) -> Self {
87        item.0
88    }
89}
90
91impl From<String> for ChannelTopic {
92    fn from(item: String) -> Self {
93        Self(item)
94    }
95}
96
97impl From<&str> for ChannelTopic {
98    fn from(item: &str) -> Self {
99        Self(item.to_string())
100    }
101}
102
103/// Dedicated type for an identifier of a channel.
104#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
105pub struct ChannelId(u16);
106
107impl fmt::Display for ChannelId {
108    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
109        write!(f, "{}", self.0)
110    }
111}
112
113impl From<ChannelId> for u16 {
114    fn from(item: ChannelId) -> Self {
115        item.0
116    }
117}
118
119impl From<u16> for ChannelId {
120    fn from(item: u16) -> Self {
121        Self(item)
122    }
123}
124
125impl From<&u16> for ChannelId {
126    fn from(item: &u16) -> Self {
127        Self(*item)
128    }
129}
130
131/// Dedicated type for an identifier of a message.
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
133pub struct MessageId(u16);
134
135impl MessageId {
136    /// The minimum possible value for a `MessageId`.
137    pub const MIN: Self = MessageId(u16::MIN);
138
139    /// The maximum possible value for a `MessageId`.
140    pub const MAX: Self = MessageId(u16::MAX);
141}
142
143impl fmt::Display for MessageId {
144    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
145        write!(f, "{}", self.0)
146    }
147}
148
149impl From<MessageId> for u16 {
150    fn from(item: MessageId) -> Self {
151        item.0
152    }
153}
154
155impl From<u16> for MessageId {
156    fn from(item: u16) -> Self {
157        Self(item)
158    }
159}
160
161impl From<MessageId> for usize {
162    fn from(item: MessageId) -> Self {
163        item.0 as usize
164    }
165}
166
167impl From<usize> for MessageId {
168    fn from(item: usize) -> Self {
169        Self(item as u16)
170    }
171}