hide global services jank in service module

Mainly to make it easier to initialize the SERVICES global correctly in
more than one place.

Also this stuff really shouldn't live at the crate root anyway.
This commit is contained in:
Charles Hall 2024-09-24 19:48:33 -07:00
parent 1fd20cdeba
commit 032e1ca3c6
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 22 additions and 20 deletions

View file

@ -2,7 +2,7 @@
// work anyway
#![cfg_attr(not(any(feature = "sqlite", feature = "rocksdb")), allow(unused))]
use std::{process::ExitCode, sync::RwLock};
use std::process::ExitCode;
use clap::Parser;
use tracing::error;
@ -18,7 +18,7 @@ mod utils;
pub(crate) use api::ruma_wrapper::{Ar, Ra};
pub(crate) use config::Config;
pub(crate) use service::{pdu::PduEvent, Services};
pub(crate) use service::{pdu::PduEvent, services, Services};
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use tikv_jemallocator::Jemalloc;
pub(crate) use utils::error::{Error, Result};
@ -27,17 +27,6 @@ pub(crate) use utils::error::{Error, Result};
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
pub(crate) static SERVICES: RwLock<Option<&'static Services>> =
RwLock::new(None);
/// Convenient access to the global [`Services`] instance
pub(crate) fn services() -> &'static Services {
SERVICES
.read()
.unwrap()
.expect("SERVICES should be initialized when this is called")
}
/// Returns the current version of the crate with extra info if supplied
///
/// Set the environment variable `GRAPEVINE_VERSION_EXTRA` to any UTF-8 string