[][src]Struct twitchchat::Tags

pub struct Tags<'a> { /* fields omitted */ }

Tags are IRCv3 message tags. Twitch uses them extensively.

This type is usually obstained temporarily from ::tags() call on a message type.

This type is intentionall very cheap and just borrows a pre-computed set of indices and a wrapped string

Implementations

impl<'a> Tags<'a>[src]

pub fn from_data_indices(data: &'a Str<'a>, indices: &'a TagIndices) -> Self[src]

Build the tags view from this borrowed Str and an associated TagIndices

pub fn raw_tags(&self) -> &'a str[src]

Gets the raw string that represents the tags

pub fn len(&self) -> usize[src]

Returns how many tags were parsed

pub fn is_empty(&self) -> bool[src]

Returns whether there are any tags

pub fn get<K: ?Sized>(&self, key: &K) -> Option<&'a str> where
    K: Borrow<str>, 
[src]

Tries to get this key

pub fn get_parsed<K: ?Sized, E>(&self, key: &K) -> Option<E> where
    K: Borrow<str>,
    E: FromStr
[src]

Tries to get the tag as a parsable FromStr type.

This returns None if it cannot parse, or cannot find the tag

let input: Str<'_> = "@foo=42;color=#1E90FF".into();
let indices = TagIndices::build_indices(&*input);
let tags = Tags::from_data_indices(&input, &indices);

// 'foo' can be parsed as a usize
let answer: usize = tags.get_parsed("foo").unwrap();
assert_eq!(answer, 42);

// 'foo' can be parsed a String (this shows how to use this with a 'turbofish')
assert_eq!(
    tags.get_parsed::<_, String>("foo").unwrap(),
    "42".to_string()
);

// 'foo' cannot be parsed as a bool
assert!(tags.get_parsed::<_, bool>("foo").is_none());

// a non-std type with a FromStr impl
let color: Color = tags.get_parsed("color").unwrap();
assert_eq!(color.rgb, RGB(0x1E, 0x90, 0xFF));

pub fn get_as_bool<K: ?Sized>(&self, key: &K) -> bool where
    K: Borrow<str>, 
[src]

Tries to get the tag as a bool.

If it wasn't found it'll return false

let input: Str<'_> = "@foo=42;ok=true;nope=false;test=1;not_test=0".into();
let indices = TagIndices::build_indices(&*input);
let tags = Tags::from_data_indices(&input, &indices);

// key 'foo' is not a bool
assert!(!tags.get_as_bool("foo"));

// key 'ok' is a bool and is true
assert!(tags.get_as_bool("ok"));

// key 'nope' is a bool but its false
assert!(!tags.get_as_bool("nope"));

// key 'test' is 1, which is true
assert!(tags.get_as_bool("test"));

// key 'not_test' is 0, which is false
assert!(!tags.get_as_bool("not_test"));

// missing key 'foobar' is missing, which is false
assert!(!tags.get_as_bool("this-key-is-missing"));

pub fn iter(&self) -> TagsIter<'_>

Notable traits for TagsIter<'a>

impl<'a> Iterator for TagsIter<'a> type Item = (&'a str, &'a str);
[src]

Get an iterator over all of the key, value pairs of tags

Trait Implementations

impl<'a> Clone for Tags<'a>[src]

impl<'a> Debug for Tags<'a>[src]

impl<'a> IntoIterator for &'a Tags<'a>[src]

type Item = (&'a str, &'a str)

The type of the elements being iterated over.

type IntoIter = TagsIter<'a>

Which kind of iterator are we turning this into?

impl<'a> PartialEq<Tags<'a>> for Tags<'a>[src]

impl<'a> Serialize for Tags<'a>[src]

impl<'a> StructuralPartialEq for Tags<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Tags<'a>

impl<'a> Send for Tags<'a>

impl<'a> Sync for Tags<'a>

impl<'a> Unpin for Tags<'a>

impl<'a> UnwindSafe for Tags<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.