src/handlers/formatters/formatter.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source (jump to first uncovered line) |
|---|---|---|
| 1 | // | |
| 2 | // File Name: 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 | //! # Formatter | |
| 26 | //! | |
| 27 | ||
| 28 | use ::fmt; | |
| 29 | use super::*; | |
| 30 | ||
| 31 | /// | |
| 32 | /// Provides wrappers for holding each type of formatter. | |
| 33 | /// | |
| 34 | #[derive(,)] | |
| 35 | pub enum Formatter { | |
| 36 | ||
| 37 | /// | |
| 38 | /// ISO 8601 / RFC 3339 date & time format. | |
| 39 | /// | |
| 40 | (), | |
| 41 | ||
| 42 | /// | |
| 43 | /// Simple format. | |
| 44 | /// | |
| 45 | (), | |
| 46 | ||
| 47 | /// | |
| 48 | /// Unix Timestamp format. | |
| 49 | /// | |
| 50 | (), | |
| 51 | ||
| 52 | /// | |
| 53 | /// Custom format. | |
| 54 | /// | |
| 55 | /// Used to hold user provided formatter. | |
| 56 | /// | |
| 57 | (<>), | |
| 58 | } | |
| 59 | ||
| 60 | impl Formatter { | |
| 61 | /// | |
| 62 | /// Format the text of the `log_entry`, in accordance with the formatting | |
| 63 | /// for this [formatter](enum.Formatter.html). | |
| 64 | /// | |
| 65 | /// ## Parameters | |
| 66 | /// - `log_entry` - The log entry to be formatted. | |
| 67 | /// | |
| 68 | 157 | pub fn format(&selflog_entry: &) -> { |
| 69 | 157 | match self { |
| 70 | 57 | ::() =>format(), |
| 71 | 92 | ::() =>format(), |
| 72 | 3 | ::() =>format(), |
| 73 | 5 | ::() =>format(), |
| 74 | } | |
| 75 | 157 | } |
| 76 | ||
| 77 | #[allow()] | |
| 78 | 4 | pub(crate) fn width(&self) -> usize { |
| 79 | 4 | 15 |
| 80 | 4 | } |
| 81 | } | |
| 82 | ||
| 83 | impl for Formatter { | |
| 84 | 1 | fn default() -> Self { |
| 85 | 1 | ::()create(None) |
| 86 | 1 | } |
| 87 | } | |
| 88 | ||
| 89 | impl ::for Formatter { | |
| 90 | 22 | fn fmt(&selff: &mut ::<_>) -> :: { |
| 91 | 22 | match self { |
| 92 | 3 | ::() =>fmt(), |
| 93 | 14 | ::() =>fmt(), |
| 94 | 1 | ::() =>fmt(), |
| 95 | 4 | ::() =>fmt(), |
| 96 | } | |
| 97 | 22 | } |
| 98 | } |