crunchyroll_rs/media/
mod.rs

1//! All media items like series, episodes or movies.
2
3mod anime;
4mod r#impl;
5mod media_collection;
6mod music;
7mod shared;
8mod stream;
9mod util;
10
11pub use anime::*;
12pub use media_collection::*;
13pub use music::*;
14pub use shared::*;
15pub use stream::*;
16
17use crate::common::Request;
18use crate::crunchyroll::Executor;
19use crate::internal::sealed::Sealed;
20use crate::{Crunchyroll, Result};
21use std::sync::Arc;
22
23/// Trait every media struct ([`Series`], [`Season`], [`Episode`], [`MovieListing`], [`Movie`],
24/// [`MusicVideo`], [`Concert`]) implements.
25pub trait Media: Request + Sealed + Into<MediaCollection> {
26    fn from_id(
27        crunchyroll: &Crunchyroll,
28        id: impl AsRef<str> + Send,
29    ) -> impl Future<Output = Result<Self>>
30    where
31        Self: Sized;
32
33    #[doc(hidden)]
34    fn __set_executor(&mut self, executor: Arc<Executor>) -> impl Future<Output = ()>;
35
36    #[doc(hidden)]
37    fn __apply_fixes(&mut self) -> impl Future<Output = ()> {
38        async move {}
39    }
40
41    #[doc(hidden)]
42    #[cfg(feature = "experimental-stabilizations")]
43    fn __apply_experimental_stabilizations(&mut self) -> impl Future<Output = ()> {
44        async move {}
45    }
46}
47
48impl Crunchyroll {
49    pub async fn media_from_id<M: Media>(&self, id: impl AsRef<str> + Send) -> Result<M> {
50        M::from_id(self, id).await
51    }
52
53    pub async fn media_collection_from_id<S: AsRef<str>>(&self, id: S) -> Result<MediaCollection> {
54        MediaCollection::from_id(self, id).await
55    }
56}