scl_lib/lib.rs
1// SPDX-License-Identifier: EUPL-1.2
2pub mod api_objects;
3pub mod client;
4pub mod tls_config;
5
6#[cfg(feature = "single-node-utils")]
7pub mod controller_utils;
8
9pub trait LogError {
10 fn log_err(self) -> Self;
11}
12
13/// Implementation of [LogError] for `Result<T, E>` to simplify the logging of errors for calculations
14/// that can fail.
15///
16/// # Examples
17///
18/// ```
19/// use scl_lib::LogError;
20///
21/// fn error_fn() -> Result<(), String> {
22/// Err("Error Message!".to_string())
23/// }
24///
25/// fn success_fn() -> Result<(), String> {
26/// Ok(())
27/// }
28///
29/// // Writes the error message to the log output
30/// let _ = error_fn().log_err();
31/// // Writes nothing for Ok(()) results
32/// let _ = success_fn().log_err();
33/// ```
34impl<T, E: std::fmt::Display> LogError for Result<T, E> {
35 fn log_err(self) -> Self {
36 if let Err(e) = &self {
37 log::error!("Error: {}", e);
38 }
39 self
40 }
41}