[][src]Struct twitchchat::Tags

pub struct Tags<'t>(_);

Tags are IRCv3 message tags. Twitch uses them extensively.

Implementations

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

pub fn parse(input: &'t str) -> Option<Self>[src]

Parses a @k=v;k=v string into a Tags type

WARNING

Use this with caution because it doesn't valid any of the parsing logic and may panic.

This is only made public for convenience of construction Tags outside the normal use-case for this crate.

This isn't fully IRCv3 compliant

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

Tries to get the tag for this key.

Note

This doesn't clone, but rather reborrows the key as another Cow

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

Tries to get a reference to the tag for this key

Note

This is provided so you don't have to play as much type-tetris

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 = "@foo=42;color=#1E90FF";
let tags = Tags::parse(input).unwrap();

// '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 = "@foo=42;ok=true;nope=false";
let tags = Tags::parse(input).unwrap();

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

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

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

pub fn iter(&'t self) -> impl Iterator<Item = (Cow<'t, str>, Cow<'t, str>)> + '_[src]

Get an iterator over the key,value pairs in the tags

Note

This doesn't clone, but rather reborrows the key as another Cow

pub fn iter_ref(
    &self
) -> impl Iterator<Item = (&Cow<'t, str>, &Cow<'t, str>)> + '_
[src]

Get an iterator over the key,value pairs in the tags

Note

This is provided so you don't have to play as much type-tetris

pub fn keys(&'t self) -> impl Iterator<Item = Cow<'t, str>> + '_[src]

Get an iterator over the keys in the tags

Note

This doesn't clone, but rather reborrows the key as another Cow

pub fn keys_ref(&self) -> impl Iterator<Item = &Cow<'t, str>> + '_[src]

Get an iterator over the keys in the tags

Note

This is provided so you don't have to play as much type-tetris

pub fn values(&'t self) -> impl Iterator<Item = Cow<'t, str>> + '_[src]

Get an iterator over the values in the tags

Note

This doesn't clone, but rather reborrows the key as another Cow

pub fn values_ref(&self) -> impl Iterator<Item = &Cow<'t, str>> + '_[src]

Get an iterator over the values in the tags

Note

This is provided so you don't have to play as much type-tetris

pub fn into_inner(self) -> HashMap<Cow<'t, str>, Cow<'t, str>>[src]

Take ownership of the inner HashMap

Trait Implementations

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

type Owned = Tags<'static>

The owned type

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

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

impl<'t> Default for Tags<'t>[src]

impl<'de, 't> Deserialize<'de> for Tags<'t>[src]

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

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

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

Auto Trait Implementations

impl<'t> RefUnwindSafe for Tags<'t>

impl<'t> Send for Tags<'t>

impl<'t> Sync for Tags<'t>

impl<'t> Unpin for Tags<'t>

impl<'t> UnwindSafe for Tags<'t>

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[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.