mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
a1e1f40ded
Signed-off-by: June Clementine Strawberry <strawberry@puppygock.gay>
38 lines
849 B
Rust
38 lines
849 B
Rust
use std::sync::{Arc, Mutex};
|
|
|
|
use super::{
|
|
super::{Level, fmt},
|
|
Closure, Data,
|
|
};
|
|
use crate::Result;
|
|
|
|
pub fn fmt_html<S>(out: Arc<Mutex<S>>) -> Box<Closure>
|
|
where
|
|
S: std::fmt::Write + Send + 'static,
|
|
{
|
|
fmt(fmt::html, out)
|
|
}
|
|
|
|
pub fn fmt_markdown<S>(out: Arc<Mutex<S>>) -> Box<Closure>
|
|
where
|
|
S: std::fmt::Write + Send + 'static,
|
|
{
|
|
fmt(fmt::markdown, out)
|
|
}
|
|
|
|
pub fn fmt<F, S>(fun: F, out: Arc<Mutex<S>>) -> Box<Closure>
|
|
where
|
|
F: Fn(&mut S, &Level, &str, &str) -> Result<()> + Send + Sync + Copy + 'static,
|
|
S: std::fmt::Write + Send + 'static,
|
|
{
|
|
Box::new(move |data| call(fun, &mut *out.lock().expect("locked"), &data))
|
|
}
|
|
|
|
fn call<F, S>(fun: F, out: &mut S, data: &Data<'_>)
|
|
where
|
|
F: Fn(&mut S, &Level, &str, &str) -> Result<()>,
|
|
S: std::fmt::Write,
|
|
{
|
|
fun(out, &data.level(), data.span_name(), data.message()).expect("log line appended");
|
|
}
|