handshake_types/name.rs
1use std::ops::Deref;
2//TODO I'm thinking we maybe make this a primitive. Not entirely sure yet, but I think a good
3//discussion should be had on whether Name is a primitive or Type.
4//Type to wrap Handshake names for type checkking as well as helper functions.
5//TODO probably have to reimpl partialEq and Eq to just check strings.
6#[derive(PartialEq, Eq, Clone, Debug, Default)]
7pub struct Name(String);
8
9impl Name {
10 pub fn len(&self) -> usize {
11 self.0.len()
12 }
13}
14
15impl From<String> for Name {
16 fn from(name: String) -> Self {
17 Name(name)
18 }
19}
20
21impl Deref for Name {
22 type Target = str;
23
24 fn deref(&self) -> &Self::Target {
25 &self.0
26 }
27}
28
29//TODO names should not be valid beyond 63 characters. We need to replace the From<String> with a
30//real FromStr trait so that it can fail on the various rules for names.