72 lines
1.8 KiB
Rust
72 lines
1.8 KiB
Rust
use std::fmt;
|
|
use serde::Deserialize;
|
|
extern crate serde;
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SearchResult {
|
|
pub id: String,
|
|
pub name: String,
|
|
#[serde(rename(deserialize = "nameunsigned"))]
|
|
pub name_unsigned: String,
|
|
#[serde(rename(deserialize = "lastchapter"))]
|
|
pub last_chapter: String,
|
|
pub image: String,
|
|
pub author: String,
|
|
pub story_link: String
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Chapter {
|
|
pub chapter_number: String,
|
|
pub chapter_name: Option<String>,
|
|
pub domain: String
|
|
}
|
|
|
|
impl fmt::Display for Chapter {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
let mut text = format!("Chapter {}", self.chapter_number);
|
|
if self.chapter_name.is_some() {
|
|
text.push_str(&format!(": {}", self.chapter_name.as_ref().unwrap()));
|
|
}
|
|
formatter.write_str(&text)
|
|
}
|
|
}
|
|
|
|
pub struct Manga {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub authors: Vec<String>,
|
|
pub status: String,
|
|
pub last_updated: String,
|
|
pub genres: Vec<String>,
|
|
pub summary: String,
|
|
pub chapters: Vec<Chapter>
|
|
}
|
|
|
|
impl fmt::Display for Manga {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
let mut text = format!("ID: {}\nName: {}\nStatus: {}\nLast Updated: {}\nGenres: {}\nAuthors: {}\nSummary:\n{}\nChapters:",
|
|
self.id,
|
|
self.name,
|
|
self.status,
|
|
self.last_updated,
|
|
self.genres.join(", "),
|
|
self.authors.join(", "),
|
|
self.summary);
|
|
for chapter in &self.chapters {
|
|
text.push_str(&format!("\n- {}", &chapter));
|
|
}
|
|
formatter.write_str(&text)
|
|
}
|
|
}
|
|
|
|
pub struct Redirect {
|
|
pub url: String
|
|
}
|
|
|
|
pub enum MangaOption {
|
|
Manga(Manga),
|
|
Redirect(Redirect),
|
|
None
|
|
}
|