commit - 1e3e5fa47218799d88d55f8ea74d8efcfb4b09e9
commit + 921165feb60b35f5fff3c8ca30107a3fb5273c46
blob - 72221416fe6d8a073966d8c3a79e9146d60517cb
blob + f5b1b8e532a444f4930b6d44be6d74995cd94971
--- src/err.rs
+++ src/err.rs
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
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
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(")"),
/// Parse the year part of a date.
fn date_year(i: &str) -> IResult<&str, i32> {
- map_res(take(4usize), str::parse::<i32>)(i)
+ map_res(take(4_usize), str::parse::<i32>)(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::<u32>)(i)
+ map_res(take(2_usize), str::parse::<u32>)(i)
}
/// Parse a date into a [`NaiveDate`].
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<Tag>> {
map(
separated_list0(
)(i)
}
+/// Parse a task in the given string.
pub fn task(i: &str) -> IResult<&str, Task> {
map_res(
tuple((
)(i)
}
+/// Parse all the tasks in the given string, returning them as a vector.
pub fn tasks(i: &str) -> IResult<&str, Vec<Task>> {
separated_list0(line_ending, task)(i)
}
blob - d84cce2d140fa2d8efd35409315a94cb11d3ca16
blob + cc3b2ef7ab549d76a82bc2cf486bd9189329539a
--- src/types.rs
+++ src/types.rs
}
impl<'a> Task<'a> {
+ /// Create a new [`Task`].
#[must_use]
- pub fn new(
+ pub const fn new(
completed: bool,
priority: u8,
completion_date: Option<NaiveDate>,
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",
- ))?
+ ));
}
}
};