Struct Tag
pub struct Tag(/* private fields */);Expand description
A YAML tag.
Tags are used in YAML to denote the type of a value.
For example, !custom_type value has the tag !custom_type.
Tag comparison ignores a leading ! prefix, so Tag::new("!foo") == Tag::new("foo").
§Examples
use noyalib::Tag;
let tag = Tag::new("!custom");
assert_eq!(tag.as_str(), "!custom");
assert_eq!(Tag::new("!foo"), Tag::new("foo"));Implementations§
§impl Tag
impl Tag
pub fn new(tag: impl Into<String>) -> Tag
pub fn new(tag: impl Into<String>) -> Tag
Creates a new tag from a string.
§Examples
use noyalib::Tag;
let t = Tag::new("!Custom");
assert_eq!(t.as_str(), "!Custom");pub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the tag as a string slice.
The leading ! (or !!) is included; use Tag::nobang
for the unprefixed form.
§Examples
use noyalib::Tag;
assert_eq!(Tag::new("!Custom").as_str(), "!Custom");
assert_eq!(Tag::new("!!str").as_str(), "!!str");pub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the tag and returns the inner string.
§Examples
use noyalib::Tag;
let s: String = Tag::new("!Custom").into_string();
assert_eq!(s, "!Custom");pub fn nobang(&self) -> &str
pub fn nobang(&self) -> &str
Returns the tag string with a single leading ! stripped.
Strips at most one ! — the YAML 1.2 primary tag
handle. The secondary !! handle keeps one ! after the
strip (!!str → !str); use Tag::as_str().trim_start_matches('!')
if you want every ! removed.
§Examples
use noyalib::Tag;
assert_eq!(Tag::new("!Custom").nobang(), "Custom");
assert_eq!(Tag::new("!!str").nobang(), "!str");
assert_eq!(Tag::new("plain").nobang(), "plain");Trait Implementations§
§impl Ord for Tag
impl Ord for Tag
§impl PartialOrd for Tag
impl PartialOrd for Tag
impl Eq for Tag
Auto Trait Implementations§
impl Freeze for Tag
impl RefUnwindSafe for Tag
impl Send for Tag
impl Sync for Tag
impl Unpin for Tag
impl UnsafeUnpin for Tag
impl UnwindSafe for Tag
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.