1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::fmt;
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct ProtobufIdent(String);
impl From<&'_ str> for ProtobufIdent {
fn from(s: &str) -> Self {
ProtobufIdent::new(s)
}
}
impl From<String> for ProtobufIdent {
fn from(s: String) -> Self {
ProtobufIdent::new(&s)
}
}
impl fmt::Display for ProtobufIdent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.get(), f)
}
}
impl ProtobufIdent {
#[allow(dead_code)]
pub fn new(s: &str) -> ProtobufIdent {
assert!(!s.is_empty());
assert!(!s.contains("/"));
assert!(!s.contains("."));
assert!(!s.contains(":"));
assert!(!s.contains("("));
assert!(!s.contains(")"));
ProtobufIdent(s.to_owned())
}
pub fn get(&self) -> &str {
&self.0
}
pub fn into_string(self) -> String {
self.0
}
}