commit 921165feb60b35f5fff3c8ca30107a3fb5273c46 from: witcher date: Thu Jan 5 11:06:17 2023 UTC Add more clippy lints and fix them commit - 1e3e5fa47218799d88d55f8ea74d8efcfb4b09e9 commit + 921165feb60b35f5fff3c8ca30107a3fb5273c46 blob - 72221416fe6d8a073966d8c3a79e9146d60517cb blob + f5b1b8e532a444f4930b6d44be6d74995cd94971 --- src/err.rs +++ src/err.rs @@ -6,12 +6,14 @@ use thiserror::Error; +/// The general error used in the library. +#[non_exhaustive] #[derive(Debug, Error)] pub enum TodoError { - #[error("Error while parsing: {0}")] - ParsingError(&'static str), + /// The input has an incorrect format. #[error("Incorrect format: {0}")] IncorrectFormat(&'static str), - #[error("IO Error: {0}")] - IOError(#[from] std::io::Error), + /// An error occured while parsing the input. + #[error("Error while parsing: {0}")] + ParsingError(&'static str), } blob - b44f8491a66a8116ee59274632c2ef18049a6ee1 blob + 90d7b67f27f240c2226b38c47362f18ff5c422c6 --- src/lib.rs +++ src/lib.rs @@ -9,7 +9,14 @@ clippy::nursery, clippy::unwrap_used, clippy::expect_used, - clippy::cargo + clippy::cargo, + clippy::style, + clippy::complexity, + clippy::correctness, + clippy::unseparated_literal_suffix, + clippy::try_err, + clippy::almost_swapped, + clippy::approx_constant )] mod err; blob - 0b8f72eed06eb2292d9328fe4a3e9719bac15589 blob + 14c752717f17798ba89ae5070c6cc6291d9f41c8 --- src/parser.rs +++ src/parser.rs @@ -36,7 +36,7 @@ fn priority(i: &str) -> IResult<&str, NonZeroU8> { map_opt( delimited( tag("("), - verify(take(1usize), |s: &str| { + verify(take(1_usize), |s: &str| { s.chars().next().map_or(false, char::is_uppercase) }), tag(")"), @@ -52,12 +52,12 @@ fn date_field_separator(i: &str) -> IResult<&str, ()> /// Parse the year part of a date. fn date_year(i: &str) -> IResult<&str, i32> { - map_res(take(4usize), str::parse::)(i) + map_res(take(4_usize), str::parse::)(i) } /// Parse the month/day part of a date. fn date_month_or_day(i: &str) -> IResult<&str, u32> { - map_res(take(2usize), str::parse::)(i) + map_res(take(2_usize), str::parse::)(i) } /// Parse a date into a [`NaiveDate`]. @@ -201,6 +201,7 @@ fn is_whitespace(c: char) -> bool { is_space(c as u8) || is_newline(c as u8) } +/// Parse all tags in the given string, which should only be the description of a task. pub fn description_tags(i: &str) -> IResult<&str, Vec> { map( separated_list0( @@ -214,6 +215,7 @@ pub fn description_tags(i: &str) -> IResult<&str, Vec< )(i) } +/// Parse a task in the given string. pub fn task(i: &str) -> IResult<&str, Task> { map_res( tuple(( @@ -227,6 +229,7 @@ pub fn task(i: &str) -> IResult<&str, Task> { )(i) } +/// Parse all the tasks in the given string, returning them as a vector. pub fn tasks(i: &str) -> IResult<&str, Vec> { separated_list0(line_ending, task)(i) } blob - d84cce2d140fa2d8efd35409315a94cb11d3ca16 blob + cc3b2ef7ab549d76a82bc2cf486bd9189329539a --- src/types.rs +++ src/types.rs @@ -164,8 +164,9 @@ pub struct Task<'a> { } impl<'a> Task<'a> { + /// Create a new [`Task`]. #[must_use] - pub fn new( + pub const fn new( completed: bool, priority: u8, completion_date: Option, @@ -295,9 +296,9 @@ impl<'a> if completed { (Some(completion_date), Some(creation_date)) } else { - Err(TodoError::IncorrectFormat( + return Err(TodoError::IncorrectFormat( "A task must be completed in order for a completion date to exist", - ))? + )); } } };