rust_anilist/models/
link.rs

1// SPDX-License-Identifier: MIT
2// Copyright (c) 2022-2025 Andriel Ferreira <https://github.com/AndrielFR>
3
4//! This module contains the `Link` struct.
5
6use serde::{Deserialize, Serialize};
7
8use super::{Color, Language};
9
10/// Represents a link.
11#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
12#[serde(rename_all(deserialize = "camelCase"))]
13pub struct Link {
14    /// The ID of the link.
15    pub id: Option<i64>,
16    /// The title of the link.
17    pub title: Option<String>,
18    /// The thumbnail of the link.
19    pub thumbnail: Option<String>,
20    /// The URL of the link.
21    pub url: String,
22    /// The site of the link.
23    pub site: String,
24    /// The ID of the site of the link.
25    pub site_id: Option<i64>,
26    /// The type of the link.
27    pub link_type: Option<LinkType>,
28    /// The language of the link.
29    pub language: Option<Language>,
30    /// The color of the link.
31    pub color: Option<Color>,
32    /// The icon of the link.
33    pub icon: Option<String>,
34    /// The notes of the link.
35    pub notes: Option<String>,
36    /// Whether the link is disabled or not.
37    pub is_disabled: Option<bool>,
38}
39
40/// Represents the type of link.
41#[derive(Debug, Default, Clone, Eq, Hash, PartialEq, Deserialize, Serialize)]
42#[serde(rename_all(deserialize = "UPPERCASE"))]
43pub enum LinkType {
44    /// The info link type.
45    #[default]
46    Info,
47    /// The streaming link type.
48    Streaming,
49    /// The social link type.
50    Social,
51}
52
53impl std::fmt::Display for LinkType {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        match self {
56            LinkType::Info => write!(f, "Info"),
57            LinkType::Streaming => write!(f, "Streaming"),
58            LinkType::Social => write!(f, "Social"),
59        }
60    }
61}