mirror of
https://github.com/JockeTF/fimfareader.git
synced 2024-11-27 07:28:00 +01:00
Save on RAM by using immutable types
This commit is contained in:
parent
6901aa3d66
commit
f2c09e14a6
1 changed files with 37 additions and 37 deletions
|
@ -22,7 +22,7 @@ pub struct Story {
|
||||||
pub archive: Archive,
|
pub archive: Archive,
|
||||||
#[serde(deserialize_with = "author_as_static")]
|
#[serde(deserialize_with = "author_as_static")]
|
||||||
pub author: Arc<Author>,
|
pub author: Arc<Author>,
|
||||||
pub chapters: Vec<Chapter>,
|
pub chapters: Box<[Chapter]>,
|
||||||
pub color: Option<Color>,
|
pub color: Option<Color>,
|
||||||
pub completion_status: CompletionStatus,
|
pub completion_status: CompletionStatus,
|
||||||
pub content_rating: ContentRating,
|
pub content_rating: ContentRating,
|
||||||
|
@ -31,7 +31,7 @@ pub struct Story {
|
||||||
pub date_published: Option<DateTime<Utc>>,
|
pub date_published: Option<DateTime<Utc>>,
|
||||||
pub date_updated: Option<DateTime<Utc>>,
|
pub date_updated: Option<DateTime<Utc>>,
|
||||||
#[serde(deserialize_with = "null_to_html")]
|
#[serde(deserialize_with = "null_to_html")]
|
||||||
pub description_html: String,
|
pub description_html: Box<str>,
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub num_chapters: i32,
|
pub num_chapters: i32,
|
||||||
pub num_comments: i32,
|
pub num_comments: i32,
|
||||||
|
@ -43,15 +43,15 @@ pub struct Story {
|
||||||
pub published: bool,
|
pub published: bool,
|
||||||
pub rating: i32,
|
pub rating: i32,
|
||||||
#[serde(deserialize_with = "null_to_text")]
|
#[serde(deserialize_with = "null_to_text")]
|
||||||
pub short_description: String,
|
pub short_description: Box<str>,
|
||||||
pub status: Status,
|
pub status: Status,
|
||||||
pub submitted: bool,
|
pub submitted: bool,
|
||||||
#[serde(deserialize_with = "tags_as_static")]
|
#[serde(deserialize_with = "tags_as_static")]
|
||||||
pub tags: Vec<Arc<Tag>>,
|
pub tags: Box<[Arc<Tag>]>,
|
||||||
#[serde(deserialize_with = "null_to_text")]
|
#[serde(deserialize_with = "null_to_text")]
|
||||||
pub title: String,
|
pub title: Box<str>,
|
||||||
pub total_num_views: i32,
|
pub total_num_views: i32,
|
||||||
pub url: String,
|
pub url: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
@ -61,51 +61,51 @@ pub struct Archive {
|
||||||
pub date_created: Option<DateTime<Utc>>,
|
pub date_created: Option<DateTime<Utc>>,
|
||||||
pub date_fetched: Option<DateTime<Utc>>,
|
pub date_fetched: Option<DateTime<Utc>>,
|
||||||
pub date_updated: Option<DateTime<Utc>>,
|
pub date_updated: Option<DateTime<Utc>>,
|
||||||
pub path: String,
|
pub path: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Author {
|
pub struct Author {
|
||||||
pub avatar: Option<Avatar>,
|
pub avatar: Option<Avatar>,
|
||||||
pub bio_html: Option<String>,
|
pub bio_html: Option<Box<str>>,
|
||||||
pub date_joined: Option<DateTime<Utc>>,
|
pub date_joined: Option<DateTime<Utc>>,
|
||||||
#[serde(deserialize_with = "string_to_id")]
|
#[serde(deserialize_with = "string_to_id")]
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: Box<str>,
|
||||||
pub num_blog_posts: Option<i32>,
|
pub num_blog_posts: Option<i32>,
|
||||||
pub num_followers: Option<i32>,
|
pub num_followers: Option<i32>,
|
||||||
pub num_stories: Option<i32>,
|
pub num_stories: Option<i32>,
|
||||||
pub url: String,
|
pub url: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Avatar {
|
pub struct Avatar {
|
||||||
#[serde(rename = "16")]
|
#[serde(rename = "16")]
|
||||||
pub x16: Option<String>,
|
pub x16: Option<Box<str>>,
|
||||||
#[serde(rename = "32")]
|
#[serde(rename = "32")]
|
||||||
pub x32: Option<String>,
|
pub x32: Option<Box<str>>,
|
||||||
#[serde(rename = "48")]
|
#[serde(rename = "48")]
|
||||||
pub x48: Option<String>,
|
pub x48: Option<Box<str>>,
|
||||||
#[serde(rename = "64")]
|
#[serde(rename = "64")]
|
||||||
pub x64: Option<String>,
|
pub x64: Option<Box<str>>,
|
||||||
#[serde(rename = "96")]
|
#[serde(rename = "96")]
|
||||||
pub x96: Option<String>,
|
pub x96: Option<Box<str>>,
|
||||||
#[serde(rename = "128")]
|
#[serde(rename = "128")]
|
||||||
pub x128: Option<String>,
|
pub x128: Option<Box<str>>,
|
||||||
#[serde(rename = "160")]
|
#[serde(rename = "160")]
|
||||||
pub x160: Option<String>,
|
pub x160: Option<Box<str>>,
|
||||||
#[serde(rename = "192")]
|
#[serde(rename = "192")]
|
||||||
pub x192: Option<String>,
|
pub x192: Option<Box<str>>,
|
||||||
#[serde(rename = "256")]
|
#[serde(rename = "256")]
|
||||||
pub x256: Option<String>,
|
pub x256: Option<Box<str>>,
|
||||||
#[serde(rename = "320")]
|
#[serde(rename = "320")]
|
||||||
pub x320: Option<String>,
|
pub x320: Option<Box<str>>,
|
||||||
#[serde(rename = "384")]
|
#[serde(rename = "384")]
|
||||||
pub x384: Option<String>,
|
pub x384: Option<Box<str>>,
|
||||||
#[serde(rename = "512")]
|
#[serde(rename = "512")]
|
||||||
pub x512: Option<String>,
|
pub x512: Option<Box<str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
@ -119,8 +119,8 @@ pub struct Chapter {
|
||||||
pub num_words: i32,
|
pub num_words: i32,
|
||||||
pub published: bool,
|
pub published: bool,
|
||||||
#[serde(deserialize_with = "null_to_text")]
|
#[serde(deserialize_with = "null_to_text")]
|
||||||
pub title: String,
|
pub title: Box<str>,
|
||||||
pub url: String,
|
pub url: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -151,10 +151,10 @@ pub enum ContentRating {
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct CoverImage {
|
pub struct CoverImage {
|
||||||
pub full: String,
|
pub full: Box<str>,
|
||||||
pub large: String,
|
pub large: Box<str>,
|
||||||
pub medium: String,
|
pub medium: Box<str>,
|
||||||
pub thumbnail: String,
|
pub thumbnail: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
@ -170,29 +170,29 @@ pub enum Status {
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: Box<str>,
|
||||||
pub old_id: String,
|
pub old_id: Box<str>,
|
||||||
pub r#type: String,
|
pub r#type: Box<str>,
|
||||||
pub url: String,
|
pub url: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn null_to_html<'de, D>(d: D) -> Result<String, D::Error>
|
fn null_to_html<'de, D>(d: D) -> Result<Box<str>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
match Option::deserialize(d)? {
|
match Option::deserialize(d)? {
|
||||||
Some(text) => Ok(text),
|
Some(text) => Ok(text),
|
||||||
None => Ok(String::from("<p></p>")),
|
None => Ok(Box::from("<p></p>")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn null_to_text<'de, D>(d: D) -> Result<String, D::Error>
|
fn null_to_text<'de, D>(d: D) -> Result<Box<str>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
match Option::deserialize(d)? {
|
match Option::deserialize(d)? {
|
||||||
Some(text) => Ok(text),
|
Some(text) => Ok(text),
|
||||||
None => Ok(String::from("")),
|
None => Ok(Box::from("")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ where
|
||||||
Author::deserialize(d).map(|author| AUTHORS.intern(author))
|
Author::deserialize(d).map(|author| AUTHORS.intern(author))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tags_as_static<'de, D>(d: D) -> Result<Vec<Arc<Tag>>, D::Error>
|
fn tags_as_static<'de, D>(d: D) -> Result<Box<[Arc<Tag>]>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue