lemmy/crates/utils/src/lib.rs
Nutomic 328a48c9f5
Remove error-type feature from lemmy-utils (#4474)
* Remove error-type feature from lemmy-utils

* fixes

---------

Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
2024-02-27 11:13:52 -05:00

54 lines
1.1 KiB
Rust

use cfg_if::cfg_if;
cfg_if! {
if #[cfg(feature = "full")] {
pub mod apub;
pub mod cache_header;
pub mod email;
pub mod rate_limit;
pub mod request;
pub mod response;
pub mod settings;
pub mod utils;
pub mod version;
}
}
pub mod error;
pub use error::LemmyErrorType;
use std::time::Duration;
pub type ConnectionId = usize;
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
#[macro_export]
macro_rules! location_info {
() => {
format!(
"None value at {}:{}, column {}",
file!(),
line!(),
column!()
)
};
}
#[cfg(feature = "full")]
/// tokio::spawn, but accepts a future that may fail and also
/// * logs errors
/// * attaches the spawned task to the tracing span of the caller for better logging
pub fn spawn_try_task(
task: impl futures::Future<Output = Result<(), error::LemmyError>> + Send + 'static,
) {
use tracing::Instrument;
tokio::spawn(
async {
if let Err(e) = task.await {
tracing::warn!("error in spawn: {e}");
}
}
.in_current_span(), // this makes sure the inner tracing gets the same context as where spawn was called
);
}