timelog/lib.rs
1//! System for logging time entries in a text-log-based format.
2//!
3//! The [`rtimelog`](../rtimelog/index.html) application applies these concepts as a command line
4//! tool.
5//!
6//! This library supports the various concepts that go into making a timelog.
7//! The core functionality is based around the concepts:
8//!
9//! - [`Day`](day::Day) - a container for events that we wish to track
10//! - [`Entry`](entry::Entry) - a task to be accomplished as a continuous chunk of time
11//! - [`Logfile`](logfile::Logfile) - list of all the that events started by the program
12//! - [`Stack`](stack::Stack) - a stack of tasks that we may want to go back to
13//!
14//! Further support for working these events is supplied by:
15//!
16//! - [`Cli`](cli::Cli) - Handles the functionality provided by the command line tool
17//! - [`Config`](config::Config) - Wrap the configuration information in an object
18//! - [`Date`](date::Date) - A utility type that simplifies working with dates (including parsing,
19//! etc.)
20//! - [`DateRange`](date::DateRange) - A pair of [`Date`]s representing a half-open range of days.
21//! - [`DateTime`](date::DateTime) - A utility type that simplifies working with date/times
22//! (including parsing, etc.)
23//! - [`Error`](error::Error) - an enumeration of the errors that can be encountered in processing
24//! timelogs
25//! - [`Result`] - Result specialized for [`Error`](error::Error)
26//! - [`TaskEvent`](task::TaskEvent) - Type representing a single entry tracked by timelog.
27//! - [`TaskLineIter`](task_line_iter::TaskLineIter) - an iterator for walking the entry lines in a
28//! timelog file
29
30#![warn(clippy::cast_lossless)]
31#![warn(clippy::return_self_not_must_use)]
32#![warn(clippy::uninlined_format_args)]
33#![warn(clippy::unwrap_used)]
34
35pub(crate) mod archive;
36pub mod chart;
37pub mod cli;
38pub mod config;
39pub mod date;
40pub mod day;
41pub mod entry;
42pub mod error;
43pub mod file;
44pub mod logfile;
45pub(crate) mod macros;
46pub mod stack;
47pub mod task;
48pub mod task_line_iter;
49
50/// Command line parser and application driver
51pub use cli::Cli;
52
53/// Wrapper for configuration information
54pub use config::Config;
55/// Wrapper for Dates as used in the crate
56pub use date::Date;
57/// Wrapper for a range of Dates.
58pub use date::DateRange;
59/// Wrapper for Date/Times as used in the crate
60pub use date::DateTime;
61/// Represention of a day as a set of times, entries, and durations.
62pub use day::Day;
63/// Module representing an entry in the timelog
64pub use entry::Entry;
65/// An error that occurs in the working with timelogs
66pub use error::Error;
67/// Interface to the logfile for the timelog application.
68pub use logfile::Logfile;
69/// Interface to the stack file for the timelog application.
70pub use stack::Stack;
71/// Type representing a single task entry.
72pub use task::TaskEvent;
73/// Iterator for walking task lines
74pub use task_line_iter::TaskLineIter;
75
76/// Result type for timelog
77pub type Result<T> = std::result::Result<T, Error>;
78
79use std::fs;
80use std::io::{BufRead, BufReader};
81use std::result;
82
83// Utility function for dealing with the mess around the BufReader
84pub(crate) fn buf_reader(file: fs::File) -> impl Iterator<Item = String> {
85 BufReader::new(file)
86 .lines()
87 .map_while(result::Result::ok)
88 .filter(|ln| !Entry::is_comment_line(ln))
89}