[][src]Struct rustube::id::Id

pub struct Id<'a>(_);

A wrapper around a Cow<'a, str> that makes sure the video id, which is contained, always has the correct format.

Guaranties:

Since YouTube does not guarantee a consistent video-id format, these guarantees can change in major version updates. If your application depends on them, make sure to check this section on regular bases!

  • The id will always match following regex (defined in ID_PATTERN): ^[a-zA-Z0-9_-]{11}$
  • The id can always be used as a valid url segment
  • The id can always be used as a valid url parameter

Ownership

All available constructors except for Id::deserialize and Id::from_string will create the borrowed version with the lifetime of the input. Therefore no allocation is required.

If you don't need 'static deserialization, you can use Id::deserialize_borrowed, which will create an Id<'de>.

If you require Id to be owned (Id<'static>), you can use Id::as_owned or Id::into_owned, which both can easily be chained. You can also use IdBuf, which is an alias for Id<'static>, to make functions and types less verbose.

Implementations

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

pub fn from_raw(raw: &'a str) -> Result<Self>[src]

pub fn from_str(id: &'a str) -> Result<Self>[src]

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

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

pub fn make_owned(&mut self) -> &mut Self[src]

pub fn into_owned(self) -> IdBuf[src]

pub fn as_owned(&self) -> IdBuf[src]

pub fn as_static(&'a self) -> &'a IdBuf[src]

Creates an &IdBuf from an arbitrary Id.

By just returning a reference, &IdBuf cannot outlive Id, even if the original string might still live:

let string = String::from("12345678910");
// create a borrowed Id bound to the live time of string 
let id: Id = Id::from_raw(&string).unwrap();
// create a reference to an IdBuf bound to the lifetime of id
let id_static: &Id<'static> = id.as_static();
// give ownership of id away | this **must** also invalidate id_static
let id_buf = id.into_owned();
// trying to access id_static now, throws a compile time error
let str_static = id_static.as_str();

pub fn as_borrowed(&'a self) -> Self[src]

pub fn as_str(&self) -> &str[src]

pub fn watch_url(&self) -> Url[src]

pub fn embed_url(&self) -> Url[src]

pub fn share_url(&self) -> Url[src]

impl Id<'static>[src]

pub fn from_string(id: String) -> Result<Self, String>[src]

impl<'de> Id<'de>[src]

pub fn deserialize_borrowed<D>(
    deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
    D: Deserializer<'de>, 
[src]

Trait Implementations

impl AsRef<str> for Id<'_>[src]

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

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

impl Deref for Id<'_>[src]

type Target = str

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for Id<'static>[src]

impl Display for Id<'_>[src]

impl Eq for Id<'_>[src]

impl<'a> Hash for Id<'a>[src]

impl Ord for Id<'_>[src]

impl<T> PartialEq<T> for Id<'_> where
    T: AsRef<str>, 
[src]

impl<T> PartialOrd<T> for Id<'_> where
    T: AsRef<str>, 
[src]

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

Auto Trait Implementations

impl<'a> RefUnwindSafe for Id<'a>[src]

impl<'a> Send for Id<'a>[src]

impl<'a> Sync for Id<'a>[src]

impl<'a> Unpin for Id<'a>[src]

impl<'a> UnwindSafe for Id<'a>[src]

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<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

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

impl<T> Instrument for T[src]

impl<T> Instrument 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> ToString for T where
    T: Display + ?Sized
[src]

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.