Skip to main content

rust_dicore/
registration.rs

1use crate::entry::IServiceResolver;
2use crate::lifetime::ServiceLifetime;
3use std::any::{Any, TypeId};
4use std::sync::Arc;
5
6/// A runtime service registration collected via `inventory::submit!`.
7/// Each `#[rust_dicore::inject(...)]` on a struct generates one submission.
8///
9/// `type_name_fn` is a function pointer (not a string) to avoid requiring
10/// `std::any::type_name::<T>()` in a const context (tracking issue #63084).
11/// The function is called at runtime by `from_injected()`.
12pub struct ServiceRegistration {
13    pub lifetime: ServiceLifetime,
14    pub type_id: TypeId,
15    pub type_name_fn: fn() -> &'static str,
16    pub factory: fn(&dyn IServiceResolver) -> Arc<dyn Any + Send + Sync>,
17}
18
19// Safety: fn pointers + enum + TypeId are all Send + Sync + 'static
20inventory::collect!(ServiceRegistration);