1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: MIT↴
// Copyright (c) 2022-2025 Andriel Ferreira <https://github.com/AndrielFR>↴
//! This module contains the `Media` enum.
use serde::{Deserialize, Serialize};
use super::{Anime, Format, Manga};
/// Represents different types of media.
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub enum Media {
/// Represents an anime media type.
Anime(Anime),
/// Represents a manga media type.
Manga(Manga),
/// Represents an unknown media type.
///
/// This variant is used when the media type is unknown or unsupported.
#[default]
Unknown,
}
impl Media {
/// Returns the id of the media.
pub fn id(&self) -> i64 {
match self {
Media::Anime(anime) => anime.id,
Media::Manga(manga) => manga.id,
Media::Unknown => 0,
}
}
/// Returns the title of the media.
pub fn title(&self) -> &str {
match self {
Media::Anime(anime) => anime.title.romaji(),
Media::Manga(manga) => manga.title.romaji(),
Media::Unknown => "Unknown",
}
}
/// Returns the format of the media.
pub fn format(&self) -> Option<&Format> {
match self {
Media::Anime(anime) => Some(&anime.format),
Media::Manga(manga) => Some(&manga.format),
Media::Unknown => None,
}
}
}
impl From<Anime> for Media {
fn from(anime: Anime) -> Self {
Media::Anime(anime)
}
}
impl From<Manga> for Media {
fn from(manga: Manga) -> Self {
Media::Manga(manga)
}
}