src/handlers/handler.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source (jump to first uncovered line) |
|---|---|---|
| 1 | // | |
| 2 | // File Name: handler.rs | |
| 3 | // Directory: src/handlers | |
| 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 | //! # Handler | |
| 26 | //! | |
| 27 | ||
| 28 | // #![allow(unused)] | |
| 29 | pub mod handler_trait; | |
| 30 | ||
| 31 | use ::{, ::, ::}; | |
| 32 | pub use ::HandlerTrait; | |
| 33 | ||
| 34 | /// | |
| 35 | /// Available handlers. | |
| 36 | /// | |
| 37 | #[derive(,,,,,)] | |
| 38 | pub enum Handler { | |
| 39 | /// | |
| 40 | /// Refers to the `ConsoleHandler` => `ConsoleType::StdOut`. | |
| 41 | /// | |
| 42 | #[default] | |
| 43 | , | |
| 44 | /// | |
| 45 | /// Refers to the `ConsoleHandler` => `ConsoleType::StdErr`. | |
| 46 | /// | |
| 47 | , | |
| 48 | /// | |
| 49 | /// Refers to the `FileHandler`. | |
| 50 | /// | |
| 51 | , | |
| 52 | /// | |
| 53 | /// Refers to the `ConsoleHandler` => `ConsoleType::Production`. | |
| 54 | /// | |
| 55 | , | |
| 56 | /// | |
| 57 | /// Refers to the `StringHandler`. | |
| 58 | /// | |
| 59 | String, | |
| 60 | /// | |
| 61 | /// Refers to a custom handler; by default: `MockHandler`. | |
| 62 | /// | |
| 63 | (String), | |
| 64 | } | |
| 65 | ||
| 66 | impl ::for Handler { | |
| 67 | 10 | fn fmt(&selff: &mut ::<_>) -> :: { |
| 68 | 10 | let= match &self { |
| 69 | 2 | ::=> "Console", |
| 70 | 1 | ::=> "EConsole", |
| 71 | 2 | ::=> "File", |
| 72 | 1 | ::=> "PConsole", |
| 73 | 2 | ::=> "String", |
| 74 | 2 | ::() => &format!("Custom({label})"), |
| 75 | }; | |
| 76 | ||
| 77 | 10 | write!( "Handler::{text}") |
| 78 | 10 | } |
| 79 | } | |
| 80 | ||
| 81 | #[cfg()] | |
| 82 | mod test { | |
| 83 | use super::; | |
| 84 | ||
| 85 | #[test] | |
| 86 | 1 | fn handlers() { |
| 87 | 1 | let= ::; |
| 88 | 1 | let= ::; |
| 89 | 1 | let= ::; |
| 90 | 1 | let= ::; |
| 91 | 1 | let= ::; |
| 92 | 1 | let= ::("MyCustom"to_string()); |
| 93 | ||
| 94 | 1 | assert_eq!(to_string(), "Handler::Console"to_string()); |
| 95 | 1 | assert_eq!(to_string(), "Handler::EConsole"to_string()); |
| 96 | 1 | assert_eq!(to_string(), "Handler::PConsole"to_string()); |
| 97 | 1 | assert_eq!(to_string(), "Handler::File"to_string()); |
| 98 | 1 | assert_eq!(to_string(), "Handler::String"to_string()); |
| 99 | 1 | assert_eq!(to_string(), "Handler::Custom(MyCustom)"to_string()); |
| 100 | 1 | } |
| 101 | } |