• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::libyaml::cstr;
2 use std::fmt::{self, Debug};
3 use std::ops::Deref;
4 
5 #[derive(Ord, PartialOrd, Eq, PartialEq)]
6 pub(crate) struct Tag(pub(in crate::libyaml) Box<[u8]>);
7 
8 impl Tag {
9     pub const NULL: &'static str = "tag:yaml.org,2002:null";
10     pub const BOOL: &'static str = "tag:yaml.org,2002:bool";
11     pub const INT: &'static str = "tag:yaml.org,2002:int";
12     pub const FLOAT: &'static str = "tag:yaml.org,2002:float";
13 }
14 
15 impl Tag {
starts_with(&self, prefix: &str) -> bool16     pub fn starts_with(&self, prefix: &str) -> bool {
17         self.0.starts_with(prefix.as_bytes())
18     }
19 }
20 
21 impl PartialEq<str> for Tag {
eq(&self, other: &str) -> bool22     fn eq(&self, other: &str) -> bool {
23         *self.0 == *other.as_bytes()
24     }
25 }
26 
27 impl Deref for Tag {
28     type Target = [u8];
deref(&self) -> &Self::Target29     fn deref(&self) -> &Self::Target {
30         &self.0
31     }
32 }
33 
34 impl Debug for Tag {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result35     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
36         cstr::debug_lossy(&self.0, formatter)
37     }
38 }
39