summaryrefslogtreecommitdiffstats
path: root/src/log.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-11-01 16:48:02 +0100
committerqkzk <qu3nt1n@gmail.com>2023-11-01 16:48:02 +0100
commit422f48502badaf438b23797f71482a2a25170b0b (patch)
tree84dd9b545e37669f225dd80182c01480214f70db /src/log.rs
parent2486f847db8a603b6da8a4ca892e80d498d40c6b (diff)
accept string or str
Diffstat (limited to 'src/log.rs')
-rw-r--r--src/log.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/log.rs b/src/log.rs
index f917590..081918d 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -74,16 +74,22 @@ pub fn read_last_log_line() -> String {
/// Write a new log line to the global variable `LAST_LOG_LINE`.
/// It uses `lazy_static` to manipulate the global variable.
/// Fail silently if the global variable can't be written.
-fn write_last_log_line(log: &str) {
+fn write_last_log_line<S>(log: S)
+where
+ S: Into<String> + std::fmt::Display,
+{
let Ok(mut new_log_line) = LAST_LOG_LINE.write() else {
return;
};
- *new_log_line = log.to_owned();
+ *new_log_line = log.to_string();
}
/// Write a line to both the global variable `LAST_LOG_LINE` and the special log
/// which can be displayed with Alt+l
-pub fn write_log_line(log_line: String) {
+pub fn write_log_line<S>(log_line: S)
+where
+ S: Into<String> + std::fmt::Display,
+{
log::info!(target: "special", "{log_line}");
- write_last_log_line(&log_line);
+ write_last_log_line(log_line);
}