[−][src]Struct rustube::id::Id
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]
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
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]
impl<'de> Deserialize<'de> for Id<'static>
[src]
pub fn deserialize<D>(
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
[src]
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
impl Display for Id<'_>
[src]
impl Eq for Id<'_>
[src]
impl<'a> Hash for Id<'a>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Id<'_>
[src]
pub fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T> PartialEq<T> for Id<'_> where
T: AsRef<str>,
[src]
T: AsRef<str>,
impl<T> PartialOrd<T> for Id<'_> where
T: AsRef<str>,
[src]
T: AsRef<str>,
pub fn partial_cmp(&self, other: &T) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,