summaryrefslogtreecommitdiff
path: root/src/directive/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/directive/mod.rs')
-rw-r--r--src/directive/mod.rs34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/directive/mod.rs b/src/directive/mod.rs
index ee96bfc..4697663 100644
--- a/src/directive/mod.rs
+++ b/src/directive/mod.rs
@@ -26,39 +26,47 @@ impl TryFrom<ParsedDirective> for Directive {
type Error = SiteError;
fn try_from(p: ParsedDirective) -> Result<Self, Self::Error> {
+ Self::try_from(&p)
+ }
+}
+
+impl TryFrom<&ParsedDirective> for Directive {
+ type Error = SiteError;
+
+ fn try_from(p: &ParsedDirective) -> Result<Self, Self::Error> {
let d = match p.name() {
"simple" => {
- Self::check_args(&p, &[], &[], false)?;
+ Self::check_args(p, &[], &[], false)?;
Directive::Simple
}
"unnamedarg" => {
- Self::check_args(&p, &[], &[], true)?;
+ Self::check_args(p, &[], &[], true)?;
Directive::UnnamedArg
}
"simplearg" => {
- Self::check_args(&p, &["foo"], &[], false)?;
+ Self::check_args(p, &["foo"], &[], false)?;
Directive::SimpleArg
}
"quotedarg" => {
- Self::check_args(&p, &["bar"], &[], false)?;
+ Self::check_args(p, &["bar"], &[], false)?;
Directive::QuotedArg
}
"multilinearg" => {
- Self::check_args(&p, &["yo"], &["then", "else"], false)?;
+ Self::check_args(p, &["yo"], &["then", "else"], false)?;
Directive::MultilineArg
}
"brokenlinks" => {
- Self::check_args(&p, BrokenLinks::REQUIRED, BrokenLinks::ALLOWED, BrokenLinks::ALLOW_ANY_UNNAMED)?;
+ Self::check_args(p, BrokenLinks::REQUIRED, BrokenLinks::ALLOWED, BrokenLinks::ALLOW_ANY_UNNAMED)?;
Directive::BrokenLinks(BrokenLinks::from(p))
}
"img" => {
- Self::check_args(&p, Img::REQUIRED, Img::ALLOWED, Img::ALLOW_ANY_UNNAMED)?;
+ Self::check_args(p, Img::REQUIRED, Img::ALLOWED, Img::ALLOW_ANY_UNNAMED)?;
Directive::Img(Img::from(p))
}
"inline" => {
Self::check_args(
- &p,
+ p,
Inline::REQUIRED,
Inline::ALLOWED,
Inline::ALLOW_ANY_UNNAMED,
@@ -66,12 +74,12 @@ impl TryFrom<ParsedDirective> for Directive {
Directive::Inline(Inline::from(p))
}
"meta" => {
- Self::check_args(&p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?;
+ Self::check_args(p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?;
Directive::Meta(Meta::from(p))
}
"pagestats" => {
Self::check_args(
- &p,
+ p,
PageStats::REQUIRED,
PageStats::ALLOWED,
PageStats::ALLOW_ANY_UNNAMED,
@@ -79,15 +87,15 @@ impl TryFrom<ParsedDirective> for Directive {
Directive::PageStats(PageStats::from(p))
}
"shortcut" => {
- Self::check_args(&p, Shortcut::REQUIRED, Shortcut::ALLOWED, Shortcut::ALLOW_ANY_UNNAMED)?;
+ Self::check_args(p, Shortcut::REQUIRED, Shortcut::ALLOWED, Shortcut::ALLOW_ANY_UNNAMED)?;
Directive::Shortcut(Shortcut::from(p))
}
"tag" => {
- Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?;
+ Self::check_args(p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?;
Directive::Tag(Tag::from(p))
}
"toc" => {
- Self::check_args(&p, Toc::REQUIRED, Toc::ALLOWED, Toc::ALLOW_ANY_UNNAMED)?;
+ Self::check_args(p, Toc::REQUIRED, Toc::ALLOWED, Toc::ALLOW_ANY_UNNAMED)?;
Directive::Toc(Toc::from(p))
}
_ => return Err(SiteError::UnknownDirective(p.name().into())),