serde_yaml/libyaml/
tag.rs
1use crate::libyaml::cstr;
2use std::fmt::{self, Debug};
3use std::ops::Deref;
4
5#[derive(Ord, PartialOrd, Eq, PartialEq)]
6pub(crate) struct Tag(pub(in crate::libyaml) Box<[u8]>);
7
8impl 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
15impl Tag {
16 pub fn starts_with(&self, prefix: &str) -> bool {
17 self.0.starts_with(prefix.as_bytes())
18 }
19}
20
21impl PartialEq<str> for Tag {
22 fn eq(&self, other: &str) -> bool {
23 *self.0 == *other.as_bytes()
24 }
25}
26
27impl Deref for Tag {
28 type Target = [u8];
29 fn deref(&self) -> &Self::Target {
30 &self.0
31 }
32}
33
34impl Debug for Tag {
35 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
36 cstr::debug_lossy(&self.0, formatter)
37 }
38}