1use std::io::BufReader;
4use std::fs::File;
5use std::time::Duration;
6
7use std::path::PathBuf;
8
9pub const DEFAULT_ROTATION_CHECK_WAIT_MILLIS: u64 = 100;
10pub const DEFAULT_NOT_ROTATED_WAIT_MILLIS: u64 = 50;
11
12#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
13#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
14pub struct Line(pub usize);
15
16#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
17#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
18pub struct Pos(pub u64);
19
20#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
21#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
22pub(crate) struct FileId(pub(crate) u64);
23
24#[derive(Debug, Clone)]
26#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
27pub struct Chaser {
28 pub line: Line,
30 pub path: PathBuf,
32 pub initial_no_file_wait: Duration,
35 pub initial_no_file_attempts: Option<usize>,
38 pub rotation_check_wait: Duration,
41 pub rotation_check_attempts: Option<usize>,
44 pub not_rotated_wait: Duration,
47}
48
49#[derive(Debug)]
50pub(crate) struct Chasing<'a> {
51 pub(crate) chaser: &'a mut Chaser,
52 pub(crate) file_id: FileId,
53 pub(crate) reader: BufReader<File>,
54 pub(crate) buffer: String,
55 pub(crate) line: Line,
56 pub(crate) pos: Pos,
57}
58
59impl Chaser {
60 pub fn new<S>(path: S) -> Chaser
62 where
63 S: Into<PathBuf>,
64 {
65 Chaser {
66 line: Line(0),
67 path: path.into(),
68 initial_no_file_attempts: None,
69 initial_no_file_wait: Duration::from_millis(DEFAULT_ROTATION_CHECK_WAIT_MILLIS),
70 rotation_check_attempts: None,
71 rotation_check_wait: Duration::from_millis(DEFAULT_ROTATION_CHECK_WAIT_MILLIS),
72 not_rotated_wait: Duration::from_millis(DEFAULT_NOT_ROTATED_WAIT_MILLIS),
73 }
74 }
75}