ibdl_common/post/
rating.rs

1//! General enum for rating posts found by the imageboard downloader
2//! # Post Rating
3//! In general, most imageboard websites also classify posts considering how explicit they are
4//!
5//! Posts are usually classified into 4 special tags:
6//! * `Safe` or `General`: Posts that don't involve anything suggestive. Usually normal fanart.
7//! * `Questionable` or `Sensitive`: Posts that involve nude/seminude characters or other suggestive art that *might* not be safe for viewing close to other people or at work.
8//! * `Explicit`: Posts that are explicitly pornographic or have other sensitive content such as gore, etc.
9//!
10
11use serde::{Deserialize, Serialize};
12use std::fmt::Display;
13
14#[derive(
15    Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default,
16)]
17pub enum Rating {
18    /// Represents posts that are don't involve anything suggestive or sensitive.
19    Safe,
20    /// Represents posts that have some degree of nudity or sexually suggestive elements.
21    Questionable,
22    /// Represents posts that have explicit elements of pornography, gore, death, etc.
23    Explicit,
24    /// Represents a failure to parse the `rating` tag into one of the above.
25    #[default]
26    Unknown,
27}
28
29impl Display for Rating {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        match self {
32            Self::Safe => write!(f, "Safe"),
33            Self::Questionable => write!(f, "Questionable"),
34            Self::Explicit => write!(f, "Explicit"),
35            Self::Unknown => write!(f, "Unknown"),
36        }
37    }
38}
39
40impl Rating {
41    /// Guess the variant according to the rating tag present in the post
42    pub fn from_rating_str(s: &str) -> Self {
43        match s {
44            "s" | "g" | "safe" | "sensitive" | "general" => Self::Safe,
45            "q" | "questionable" => Self::Questionable,
46            "e" | "explicit" => Self::Explicit,
47            _ => Self::Unknown,
48        }
49    }
50}