From ec41f376c51ad990c67015829d24daba65cd2538 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 31 Jul 2022 11:23:29 +0300 Subject: chore: reformat code Sponsored-by: author --- build.rs | 3 +-- src/bin/riki.rs | 2 +- src/directive/img.rs | 4 +--- src/directive/tag.rs | 4 +--- src/lib.rs | 12 ++++++------ src/page.rs | 13 +++++++++++-- src/parser.rs | 14 +++++++------- src/site.rs | 3 +-- src/token.rs | 27 +++++++++++++-------------- src/util.rs | 10 ++++++++-- src/wikitext.rs | 8 +------- 11 files changed, 51 insertions(+), 49 deletions(-) diff --git a/build.rs b/build.rs index da983ec..cc39391 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,3 @@ fn main() { - subplot_build::codegen("riki.md") - .expect("failed to generate code with Subplot"); + subplot_build::codegen("riki.md").expect("failed to generate code with Subplot"); } diff --git a/src/bin/riki.rs b/src/bin/riki.rs index 86d9fcf..afd43ef 100644 --- a/src/bin/riki.rs +++ b/src/bin/riki.rs @@ -48,7 +48,7 @@ struct Args { #[derive(Parser)] enum Command { Build(Build), - List(List) + List(List), } #[derive(Parser)] diff --git a/src/directive/img.rs b/src/directive/img.rs index f81f8a9..e10851e 100644 --- a/src/directive/img.rs +++ b/src/directive/img.rs @@ -16,9 +16,7 @@ impl Img { pub const ALLOW_ANY_UNNAMED: bool = true; pub fn new(src: String) -> Self { - Self { - src, - } + Self { src } } pub fn process(&self, site: &Site, meta: &mut PageMeta) -> Result { diff --git a/src/directive/tag.rs b/src/directive/tag.rs index 9486a7b..baf4561 100644 --- a/src/directive/tag.rs +++ b/src/directive/tag.rs @@ -14,9 +14,7 @@ impl Tag { pub const ALLOW_ANY_UNNAMED: bool = true; pub fn new(tags: Vec) -> Self { - Self { - tags, - } + Self { tags } } pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { diff --git a/src/lib.rs b/src/lib.rs index 781b999..2caefeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,12 +7,12 @@ //! little slow. This care implements a subset of the functionality of //! ikiwiki in Rust, for speed. -pub mod site; -pub mod page; -pub mod error; -pub mod token; -pub mod parser; -pub mod wikitext; pub mod directive; +pub mod error; pub mod html; +pub mod page; +pub mod parser; +pub mod site; +pub mod token; pub mod util; +pub mod wikitext; diff --git a/src/page.rs b/src/page.rs index c00aa54..d2f144a 100644 --- a/src/page.rs +++ b/src/page.rs @@ -126,7 +126,12 @@ pub struct PageMeta { impl PageMeta { fn new(name: String, title: Option, path: PathBuf) -> Self { - trace!("PageMeta: name={:?} title={:?} path={:?}", name, title, path); + trace!( + "PageMeta: name={:?} title={:?} path={:?}", + name, + title, + path + ); Self { name, title, path } } @@ -165,7 +170,11 @@ pub struct MetaBuilder { impl MetaBuilder { pub fn build(self) -> PageMeta { - PageMeta::new(self.name, self.title, self.path.expect("path set on MetaBuilder")) + PageMeta::new( + self.name, + self.title, + self.path.expect("path set on MetaBuilder"), + ) } pub fn name(mut self, name: String) -> Self { diff --git a/src/parser.rs b/src/parser.rs index 14f46c4..ed205e4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -120,7 +120,8 @@ impl WikitextParser { link_text.push(' '); self.tokens.drain(..1); } - [Token::ClosedBracket, Token::OpenParens, Token::Word(word), Token::ClosedParens, ..] => { + [Token::ClosedBracket, Token::OpenParens, Token::Word(word), Token::ClosedParens, ..] => + { target = Some(word.to_string()); self.tokens.drain(..4); break; @@ -314,7 +315,7 @@ mod test { let mut p = WikitextParser::new( r#"[[!multilinearg yo="""foo bar"""]]"#, - &patterns + &patterns, ); assert_eq!( p.parse().unwrap(), @@ -326,13 +327,12 @@ mod test { #[test] fn directive_multiple_args() { let patterns = TokenPatterns::default(); - let mut p = WikitextParser::new( - r#"[[!img foo.jpg class=image]]"#, - &patterns - ); + let mut p = WikitextParser::new(r#"[[!img foo.jpg class=image]]"#, &patterns); assert_eq!( p.parse().unwrap(), - Some(Snippet::Directive(Directive::Img(Img::new("foo.jpg".into())))) + Some(Snippet::Directive(Directive::Img(Img::new( + "foo.jpg".into() + )))) ); assert_eq!(p.parse().unwrap(), None); } diff --git a/src/site.rs b/src/site.rs index 48de58d..d48d94c 100644 --- a/src/site.rs +++ b/src/site.rs @@ -125,8 +125,7 @@ impl Site { fn all_files(root: &Path) -> Result, SiteError> { let mut files = vec![]; - for e in WalkDir::new(root) - { + for e in WalkDir::new(root) { let e = e.map_err(|err| SiteError::WalkDir(root.to_path_buf(), err))?; let path = e.path(); if Self::is_excluded(path) { diff --git a/src/token.rs b/src/token.rs index f5696e7..76cd7b4 100644 --- a/src/token.rs +++ b/src/token.rs @@ -49,10 +49,7 @@ pub struct TokenParser<'a> { impl<'a> TokenParser<'a> { pub fn new(input: &'a str, patterns: &'a TokenPatterns) -> Self { - Self { - input, - patterns, - } + Self { input, patterns } } pub fn parse(&mut self) -> Token { @@ -76,7 +73,7 @@ impl<'a> TokenParser<'a> { Token::Pipe } else if self.literal("=") { Token::Equals - } else if let Some(m) = self.regex(&self.patterns.spaces.clone()) { + } else if let Some(m) = self.regex(&self.patterns.spaces.clone()) { Token::Spaces(m.as_str().into()) } else if let Some(m) = self.regex(&self.patterns.triple_quoted.clone()) { Token::QuotedValue(m.as_str().into()) @@ -160,7 +157,6 @@ mod test { assert_eq!(p.parse(), Token::End); } - #[test] fn single_open_bracket() { let patterns = TokenPatterns::default(); @@ -265,10 +261,7 @@ mod test { #[test] fn simple_directive() { let patterns = TokenPatterns::default(); - let mut p = parser( - r#"[[!if test="enabled(sidebar)"]]"#, - &patterns - ); + let mut p = parser(r#"[[!if test="enabled(sidebar)"]]"#, &patterns); assert_eq!(p.parse(), Token::OpenBrackets); assert_eq!(p.parse(), Token::Bang); assert_eq!(p.parse(), Token::Word("if".into())); @@ -291,7 +284,7 @@ mod test { """ else=""" [[!inline pages=sidebar raw=yes]] """]]"#, - &patterns + &patterns, ); assert_eq!(p.parse(), Token::OpenBrackets); assert_eq!(p.parse(), Token::Bang); @@ -310,7 +303,10 @@ mod test { assert_eq!(p.parse(), Token::Spaces(" ".into())); assert_eq!(p.parse(), Token::Word("else".into())); assert_eq!(p.parse(), Token::Equals); - assert_eq!(p.parse(), Token::QuotedValue("\n[[!inline pages=sidebar raw=yes]]\n".into())); + assert_eq!( + p.parse(), + Token::QuotedValue("\n[[!inline pages=sidebar raw=yes]]\n".into()) + ); assert_eq!(p.parse(), Token::CloseBrackets); assert_eq!(p.parse(), Token::End); @@ -325,7 +321,7 @@ mod test { """ else=""" [[!inline pages=sidebar raw=yes]] """]]"#, - &patterns + &patterns, ); let mut p = orig.clone(); assert_eq!(p.parse(), Token::OpenBrackets); @@ -345,7 +341,10 @@ mod test { assert_eq!(p.parse(), Token::Spaces(" ".into())); assert_eq!(p.parse(), Token::Word("else".into())); assert_eq!(p.parse(), Token::Equals); - assert_eq!(p.parse(), Token::QuotedValue("\n[[!inline pages=sidebar raw=yes]]\n".into())); + assert_eq!( + p.parse(), + Token::QuotedValue("\n[[!inline pages=sidebar raw=yes]]\n".into()) + ); assert_eq!(p.parse(), Token::CloseBrackets); assert_eq!(p.parse(), Token::End); diff --git a/src/util.rs b/src/util.rs index fbf81f6..e1f82b3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -84,12 +84,18 @@ mod test { #[test] fn joins_relative() { - assert_eq!(join_subpath(Path::new("foo"), Path::new("bar")), PathBuf::from("foo/bar")); + assert_eq!( + join_subpath(Path::new("foo"), Path::new("bar")), + PathBuf::from("foo/bar") + ); } #[test] fn joins_absolute() { - assert_eq!(join_subpath(Path::new("foo"), Path::new("/bar")), PathBuf::from("foo/bar")); + assert_eq!( + join_subpath(Path::new("foo"), Path::new("/bar")), + PathBuf::from("foo/bar") + ); } #[test] diff --git a/src/wikitext.rs b/src/wikitext.rs index 54570fa..b425021 100644 --- a/src/wikitext.rs +++ b/src/wikitext.rs @@ -80,13 +80,7 @@ impl ParsedDirective { pub fn unnamed_args(&self) -> Vec<&str> { self.args .iter() - .filter_map(|(k, v)| { - if v.is_empty() { - Some(k.as_str()) - } else { - None - } - }) + .filter_map(|(k, v)| if v.is_empty() { Some(k.as_str()) } else { None }) .collect() } } -- cgit v1.2.1