Replaced all impl Default with derive(Default), where possible (#1141)

This commit is contained in:
Nathan West 2020-08-19 06:25:54 -04:00 committed by GitHub
parent 159ce0f672
commit 51a2213fcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 170 deletions

View file

@ -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
@ -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>;

View file

@ -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,
}
}
}

View file

@ -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
@ -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(),
}
}
}

View file

@ -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,
@ -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};

View file

@ -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,
@ -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 {
@ -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;

View file

@ -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,
@ -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(
@ -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};

View file

@ -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()),
}
};

View file

@ -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,
@ -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() }
}
}

View file

@ -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));