Skip to content

Commit

Permalink
Replaced all impl Default with derive(Default), where possible (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucretiel authored Aug 19, 2020
1 parent 159ce0f commit 51a2213
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 170 deletions.
8 changes: 1 addition & 7 deletions components/config/src/config/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use serde_derive::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct Language {
/// The language code
Expand All @@ -13,10 +13,4 @@ pub struct Language {
pub search: bool,
}

impl Default for Language {
fn default() -> Self {
Language { code: String::new(), feed: false, search: false }
}
}

pub type TranslateTerm = HashMap<String, String>;
12 changes: 1 addition & 11 deletions components/config/src/config/slugify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@ use serde_derive::{Deserialize, Serialize};

use utils::slugs::SlugifyStrategy;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct Slugify {
pub paths: SlugifyStrategy,
pub taxonomies: SlugifyStrategy,
pub anchors: SlugifyStrategy,
}

impl Default for Slugify {
fn default() -> Self {
Slugify {
paths: SlugifyStrategy::On,
taxonomies: SlugifyStrategy::On,
anchors: SlugifyStrategy::On,
}
}
}
14 changes: 1 addition & 13 deletions components/config/src/config/taxonomies.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde_derive::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct Taxonomy {
/// The name used in the URL, usually the plural
Expand Down Expand Up @@ -33,15 +33,3 @@ impl Taxonomy {
}
}
}

impl Default for Taxonomy {
fn default() -> Self {
Taxonomy {
name: String::new(),
paginate_by: None,
paginate_path: None,
feed: false,
lang: String::new(),
}
}
}
18 changes: 1 addition & 17 deletions components/library/src/content/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn find_content_components<P: AsRef<Path>>(path: P) -> Vec<String> {
}

/// Struct that contains all the information about the actual file
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct FileInfo {
/// The full path to the .md file
pub path: PathBuf,
Expand Down Expand Up @@ -143,22 +143,6 @@ impl FileInfo {
}
}

#[doc(hidden)]
impl Default for FileInfo {
fn default() -> FileInfo {
FileInfo {
path: PathBuf::new(),
parent: PathBuf::new(),
grand_parent: None,
filename: String::new(),
name: String::new(),
components: vec![],
relative: String::new(),
canonical: PathBuf::new(),
}
}
}

#[cfg(test)]
mod tests {
use std::path::{Path, PathBuf};
Expand Down
58 changes: 2 additions & 56 deletions components/library/src/content/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lazy_static! {
).unwrap();
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Page {
/// All info about the actual file
pub file: FileInfo,
Expand Down Expand Up @@ -91,31 +91,7 @@ impl Page {
pub fn new<P: AsRef<Path>>(file_path: P, meta: PageFrontMatter, base_path: &PathBuf) -> Page {
let file_path = file_path.as_ref();

Page {
file: FileInfo::new_page(file_path, base_path),
meta,
ancestors: vec![],
raw_content: "".to_string(),
assets: vec![],
serialized_assets: vec![],
content: "".to_string(),
slug: "".to_string(),
path: "".to_string(),
components: vec![],
permalink: "".to_string(),
summary: None,
earlier: None,
later: None,
lighter: None,
heavier: None,
toc: vec![],
word_count: None,
reading_time: None,
lang: String::new(),
translations: Vec::new(),
internal_links_with_anchors: Vec::new(),
external_links: Vec::new(),
}
Page { file: FileInfo::new_page(file_path, base_path), meta, ..Self::default() }
}

pub fn is_draft(&self) -> bool {
Expand Down Expand Up @@ -341,36 +317,6 @@ impl Page {
}
}

impl Default for Page {
fn default() -> Page {
Page {
file: FileInfo::default(),
meta: PageFrontMatter::default(),
ancestors: vec![],
raw_content: "".to_string(),
assets: vec![],
serialized_assets: vec![],
content: "".to_string(),
slug: "".to_string(),
path: "".to_string(),
components: vec![],
permalink: "".to_string(),
summary: None,
earlier: None,
later: None,
lighter: None,
heavier: None,
toc: vec![],
word_count: None,
reading_time: None,
lang: String::new(),
translations: Vec::new(),
internal_links_with_anchors: Vec::new(),
external_links: Vec::new(),
}
}
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;
Expand Down
54 changes: 3 additions & 51 deletions components/library/src/content/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use crate::content::has_anchor;
use crate::content::ser::SerializingSection;
use crate::library::Library;

#[derive(Clone, Debug, PartialEq)]
// Default is used to create a default index section if there is no _index.md in the root content directory
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Section {
/// All info about the actual file
pub file: FileInfo,
Expand Down Expand Up @@ -74,28 +75,7 @@ impl Section {
) -> Section {
let file_path = file_path.as_ref();

Section {
file: FileInfo::new_section(file_path, base_path),
meta,
ancestors: vec![],
path: "".to_string(),
components: vec![],
permalink: "".to_string(),
raw_content: "".to_string(),
assets: vec![],
serialized_assets: vec![],
content: "".to_string(),
pages: vec![],
ignored_pages: vec![],
subsections: vec![],
toc: vec![],
word_count: None,
reading_time: None,
lang: String::new(),
translations: Vec::new(),
internal_links_with_anchors: Vec::new(),
external_links: Vec::new(),
}
Section { file: FileInfo::new_section(file_path, base_path), meta, ..Self::default() }
}

pub fn parse(
Expand Down Expand Up @@ -266,34 +246,6 @@ impl Section {
}
}

/// Used to create a default index section if there is no _index.md in the root content directory
impl Default for Section {
fn default() -> Section {
Section {
file: FileInfo::default(),
meta: SectionFrontMatter::default(),
ancestors: vec![],
path: "".to_string(),
components: vec![],
permalink: "".to_string(),
raw_content: "".to_string(),
assets: vec![],
serialized_assets: vec![],
content: "".to_string(),
pages: vec![],
ignored_pages: vec![],
subsections: vec![],
toc: vec![],
reading_time: None,
word_count: None,
lang: String::new(),
translations: Vec::new(),
internal_links_with_anchors: Vec::new(),
external_links: Vec::new(),
}
}
}

#[cfg(test)]
mod tests {
use std::fs::{create_dir, File};
Expand Down
2 changes: 1 addition & 1 deletion components/link_checker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn check_url(url: &str, config: &LinkChecker) -> Result {
response.copy_to(&mut buf).unwrap();
match String::from_utf8(buf) {
Ok(s) => s,
Err(_) => return Err("The page didn't return valid UTF-8".to_string())
Err(_) => return Err("The page didn't return valid UTF-8".to_string()),
}
};

Expand Down
16 changes: 2 additions & 14 deletions components/rendering/src/table_of_contents.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde_derive::Serialize;

/// Populated while receiving events from the markdown parser
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, Default, PartialEq, Clone, Serialize)]
pub struct Heading {
pub level: u32,
pub id: String,
Expand All @@ -12,19 +12,7 @@ pub struct Heading {

impl Heading {
pub fn new(level: u32) -> Heading {
Heading {
level,
id: String::new(),
permalink: String::new(),
title: String::new(),
children: Vec::new(),
}
}
}

impl Default for Heading {
fn default() -> Self {
Heading::new(0)
Heading { level, ..Self::default() }
}
}

Expand Down
6 changes: 6 additions & 0 deletions components/utils/src/slugs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub enum SlugifyStrategy {
Off,
}

impl Default for SlugifyStrategy {
fn default() -> Self {
SlugifyStrategy::On
}
}

fn strip_chars(s: &str, chars: &str) -> String {
let mut sanitized_string = s.to_string();
sanitized_string.retain(|c| !chars.contains(c));
Expand Down

0 comments on commit 51a2213

Please sign in to comment.