1#![allow(clippy::tabs_in_doc_comments)]
2#![warn(unreachable_pub)]
3#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))]
4
5pub mod database;
8pub mod error;
9pub mod image;
10pub mod matrix;
11pub mod tg;
12#[cfg(feature = "ffmpeg")]
13mod video;
14
15use std::sync::OnceLock;
16
17struct Client(OnceLock<reqwest::Client>);
18static CLIENT: Client = Client(OnceLock::new());
19
20impl Client {
21 fn get(&self) -> &'static reqwest::Client {
22 if let Some(value) = CLIENT.0.get() {
23 return value;
24 };
25 set_client(reqwest::Client::default()).ok();
26 CLIENT.0.get().unwrap() }
28}
29
30pub fn set_client(client: reqwest::Client) -> Result<(), ()> {
35 init();
36 CLIENT.0.set(client).map_err(|_| ())
37}
38
39pub fn get_client() -> &'static reqwest::Client {
40 CLIENT.get()
41}
42
43fn init() {
45 #[cfg(feature = "ffmpeg")]
46 {
47 static GUARD: OnceLock<()> = OnceLock::new();
48 if GUARD.set(()).is_ok() {
51 ffmpeg::init().expect("Failed to initialise ffmpeg");
52 }
53 }
54}