src/handlers/formatters/mock_formatter.rs

Lines

100.00 %

Functions

100.00 %

Regions

100.00 %

LineCountSource (jump to first uncovered line)
1
//
2
// File Name:    mock_formatter.rs
3
// Directory:    src/handlers/formatters
4
// Project Name: flogging
5
//
6
// Copyright (C) 2025 Bradley Willcott
7
//
8
// SPDX-License-Identifier: GPL-3.0-or-later
9
//
10
// This library (crate) is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// This library (crate) is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
// GNU General Public License for more details.
19
//
20
// You should have received a copy of the GNU General Public License
21
// along with this library (crate).  If not, see <https://www.gnu.org/licenses/>.
22
//
23
24
//!
25
//! # Mock Formatter
26
//!
27
28
use std::fmt;
29
use crate::FormatTrait;
30
31
///
32
/// Mock Formatter.
33
///
34
/// Used as a filler. It does not have a proper format string. It is also used
35
/// in examples for custom formatters.
36
///
37
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
38
pub struct MockFormatter {
39
    dt_fmt: String,
40
    fmt_string: String,
41
}
42
43
impl MockFormatter {
44
    ///
45
    /// Creates a new instance of `MockFormatter`.
46
    ///
473
    pub fn new() -> Self {
483
        Self {
493
            dt_fmt: "".to_string(),
503
            fmt_string: "MockFormatter".to_string(),
513
        }
523
    }
53
54
    ///
55
    /// Returns the date/time format string.
56
    ///
573
    pub fn dt_fmt(&self) -> String {
583
        self.dt_fmt.clone()
593
    }
60
61
    ///
62
    /// Returns the primary format string.
63
    ///
642
    pub fn fmt_string(&self) -> String {
652
        self.fmt_string.clone()
662
    }
67
}
68
69
impl Default for MockFormatter {
701
    fn default() -> Self {
711
        Self::new()
721
    }
73
}
74
75
impl fmt::Display for MockFormatter {
762
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
772
        write!(f, "{}", self.fmt_string())
782
    }
79
}
80
81
impl FormatTrait for MockFormatter {
823
    fn format(&self, _log_entry: &crate::LogEntry) -> String {
833
        let _ = self.dt_fmt();
843
        "MockFormatter".to_string()
853
    }
86
}