Apply more suggestions.

This commit is contained in:
Tom Alexander 2023-10-16 16:42:34 -04:00
parent 192a4a2891
commit 728f79b86c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 19 additions and 19 deletions

View File

@ -1,15 +1,15 @@
use super::global_settings::EntityDefinition; use super::global_settings::EntityDefinition;
pub(crate) const DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS: [&'static str; 1] = ["CAPTION"]; pub(crate) const DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS: [&str; 1] = ["CAPTION"];
pub(crate) const DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS: [&'static str; 2] = ["CAPTION", "RESULTS"]; pub(crate) const DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS: [&str; 2] = ["CAPTION", "RESULTS"];
pub(crate) const DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [ pub(crate) const DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS: [&str; 13] = [
"CAPTION", "DATA", "HEADER", "HEADERS", "LABEL", "NAME", "PLOT", "RESNAME", "RESULT", "CAPTION", "DATA", "HEADER", "HEADERS", "LABEL", "NAME", "PLOT", "RESNAME", "RESULT",
"RESULTS", "SOURCE", "SRCNAME", "TBLNAME", "RESULTS", "SOURCE", "SRCNAME", "TBLNAME",
]; ];
pub(crate) const DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST: [(&'static str, &'static str); 8] = [ pub(crate) const DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST: [(&str, &str); 8] = [
("DATA", "NAME"), ("DATA", "NAME"),
("LABEL", "NAME"), ("LABEL", "NAME"),
("RESNAME", "NAME"), ("RESNAME", "NAME"),
@ -20,7 +20,7 @@ pub(crate) const DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST: [(&'static str,
("HEADERS", "HEADER"), ("HEADERS", "HEADER"),
]; ];
pub(crate) const DEFAULT_ORG_LINK_PARAMETERS: [&'static str; 23] = [ pub(crate) const DEFAULT_ORG_LINK_PARAMETERS: [&str; 23] = [
"id", "id",
"eww", "eww",
"rmail", "rmail",

View File

@ -26,6 +26,7 @@ use super::SetSource;
use super::SpecialBlock; use super::SpecialBlock;
use super::StandardProperties; use super::StandardProperties;
#[allow(clippy::large_enum_variant)]
#[derive(Debug)] #[derive(Debug)]
pub enum Element<'s> { pub enum Element<'s> {
Paragraph(Paragraph<'s>), Paragraph(Paragraph<'s>),

View File

@ -170,12 +170,10 @@ impl<'s> Paragraph<'s> {
/// ///
/// This is used for elements that support an "empty" content like greater blocks. /// This is used for elements that support an "empty" content like greater blocks.
pub(crate) fn of_text(input: &'s str) -> Self { pub(crate) fn of_text(input: &'s str) -> Self {
let mut objects = Vec::with_capacity(1);
objects.push(Object::PlainText(PlainText { source: input }));
Paragraph { Paragraph {
source: input, source: input,
affiliated_keywords: AffiliatedKeywords::default(), affiliated_keywords: AffiliatedKeywords::default(),
children: objects, children: vec![Object::PlainText(PlainText { source: input })],
} }
} }
} }

View File

@ -263,6 +263,7 @@ pub struct Superscript<'s> {
pub children: Vec<Object<'s>>, pub children: Vec<Object<'s>>,
} }
// TODO: Perhaps there is an optimization of converting to unix time we can do to shrink this struct. (ref: clippy::large_enum_variant on Element)
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct Timestamp<'s> { pub struct Timestamp<'s> {
pub source: &'s str, pub source: &'s str,
@ -315,7 +316,7 @@ pub struct Minute(MinuteInner);
impl Year { impl Year {
// TODO: Make a real error type instead of a boxed any error. // TODO: Make a real error type instead of a boxed any error.
pub fn new<'s>(source: &'s str) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(source: &str) -> Result<Self, Box<dyn std::error::Error>> {
let year = source.parse::<YearInner>()?; let year = source.parse::<YearInner>()?;
Ok(Year(year)) Ok(Year(year))
} }
@ -327,9 +328,9 @@ impl Year {
impl Month { impl Month {
// TODO: Make a real error type instead of a boxed any error. // TODO: Make a real error type instead of a boxed any error.
pub fn new<'s>(source: &'s str) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(source: &str) -> Result<Self, Box<dyn std::error::Error>> {
let month = source.parse::<MonthInner>()?; let month = source.parse::<MonthInner>()?;
if month < 1 || month > 12 { if !(1..=12).contains(&month) {
Err("Month exceeds possible range.")?; Err("Month exceeds possible range.")?;
} }
Ok(Month(month)) Ok(Month(month))
@ -342,9 +343,9 @@ impl Month {
impl DayOfMonth { impl DayOfMonth {
// TODO: Make a real error type instead of a boxed any error. // TODO: Make a real error type instead of a boxed any error.
pub fn new<'s>(source: &'s str) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(source: &str) -> Result<Self, Box<dyn std::error::Error>> {
let day_of_month = source.parse::<DayOfMonthInner>()?; let day_of_month = source.parse::<DayOfMonthInner>()?;
if day_of_month < 1 || day_of_month > 31 { if !(1..=31).contains(&day_of_month) {
Err("Day of month exceeds possible range.")?; Err("Day of month exceeds possible range.")?;
} }
Ok(DayOfMonth(day_of_month)) Ok(DayOfMonth(day_of_month))
@ -357,7 +358,7 @@ impl DayOfMonth {
impl Hour { impl Hour {
// TODO: Make a real error type instead of a boxed any error. // TODO: Make a real error type instead of a boxed any error.
pub fn new<'s>(source: &'s str) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(source: &str) -> Result<Self, Box<dyn std::error::Error>> {
let hour = source.parse::<HourInner>()?; let hour = source.parse::<HourInner>()?;
if hour > 23 { if hour > 23 {
Err("Hour exceeds possible range.")?; Err("Hour exceeds possible range.")?;
@ -372,7 +373,7 @@ impl Hour {
impl Minute { impl Minute {
// TODO: Make a real error type instead of a boxed any error. // TODO: Make a real error type instead of a boxed any error.
pub fn new<'s>(source: &'s str) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(source: &str) -> Result<Self, Box<dyn std::error::Error>> {
let minute = source.parse::<MinuteInner>()?; let minute = source.parse::<MinuteInner>()?;
if minute > 59 { if minute > 59 {
Err("Minute exceeds possible range.")?; Err("Minute exceeds possible range.")?;
@ -731,21 +732,21 @@ impl<'s> RegularLink<'s> {
/// Coalesce whitespace if the raw_link contains line breaks. /// Coalesce whitespace if the raw_link contains line breaks.
/// ///
/// This corresponds to the output you would get from the upstream emacs org-mode AST. /// This corresponds to the output you would get from the upstream emacs org-mode AST.
pub fn get_raw_link<'b>(&'b self) -> Cow<'b, str> { pub fn get_raw_link(&self) -> Cow<'_, str> {
coalesce_whitespace_if_line_break(&self.raw_link) coalesce_whitespace_if_line_break(&self.raw_link)
} }
/// Coalesce whitespace if the path contains line breaks. /// Coalesce whitespace if the path contains line breaks.
/// ///
/// This corresponds to the output you would get from the upstream emacs org-mode AST. /// This corresponds to the output you would get from the upstream emacs org-mode AST.
pub fn get_path<'b>(&'b self) -> Cow<'b, str> { pub fn get_path(&self) -> Cow<'_, str> {
coalesce_whitespace_if_line_break(&self.path) coalesce_whitespace_if_line_break(&self.path)
} }
/// Coalesce whitespace if the search_option contains line breaks. /// Coalesce whitespace if the search_option contains line breaks.
/// ///
/// This corresponds to the output you would get from the upstream emacs org-mode AST. /// This corresponds to the output you would get from the upstream emacs org-mode AST.
pub fn get_search_option<'b>(&'b self) -> Option<Cow<'b, str>> { pub fn get_search_option(&self) -> Option<Cow<'_, str>> {
self.search_option self.search_option
.as_ref() .as_ref()
.map(|search_option| coalesce_whitespace_if_line_break(search_option.borrow())) .map(|search_option| coalesce_whitespace_if_line_break(search_option.borrow()))
@ -782,7 +783,7 @@ impl<'s> OrgMacro<'s> {
pub fn get_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b { pub fn get_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b {
self.args self.args
.iter() .iter()
.map(|arg| coalesce_whitespace_escaped('\\', |c| ",".contains(c))(*arg)) .map(|arg| coalesce_whitespace_escaped('\\', |c| ",".contains(c))(arg))
} }
} }