Skip to content

Commit

Permalink
chore: make all public types impl Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandros committed Oct 16, 2024
1 parent c50a465 commit 4da13cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ferrunix-core/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ thread_local! {
///
/// This is, usually, used by the derive macro, and not manually.
#[non_exhaustive]
#[allow(missing_debug_implementations)]
#[derive(Debug)]
pub struct RegistrationFunc(pub(crate) fn(&Registry));

impl RegistrationFunc {
Expand Down
15 changes: 13 additions & 2 deletions ferrunix-core/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ enum Object {
}

/// Registry for all types that can be constructed or otherwise injected.
#[allow(missing_debug_implementations)]
pub struct Registry {
objects: RwLock<HashMap<TypeId, Object>>,
validation: RwLock<HashMap<TypeId, Validator>>,
Expand Down Expand Up @@ -230,8 +229,14 @@ impl Registry {
}
}

impl std::fmt::Debug for Registry {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fmt.debug_struct("Registry").finish()
}
}

/// A builder for objects with dependencies. This can be created by using [`Registry::with_deps`].
#[allow(missing_debug_implementations, clippy::single_char_lifetime_names)]
#[allow(clippy::single_char_lifetime_names)]
pub struct Builder<'a, T, Deps> {
registry: &'a Registry,
_marker: PhantomData<T>,
Expand Down Expand Up @@ -361,3 +366,9 @@ where
);
}
}

impl<T, Dep> std::fmt::Debug for Builder<'_, T, Dep> {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fmt.debug_struct("Builder").finish()
}
}
1 change: 1 addition & 0 deletions ferrunix/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ mod common;
mod derive_simple;
mod manual;
mod manual_traits;
mod validate_traits;
13 changes: 13 additions & 0 deletions ferrunix/tests/it/validate_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![allow(clippy::no_effect)]
use ferrunix::registry::Builder;
use ferrunix::{Registry, Singleton, Transient};

struct IsDebug<T: std::fmt::Debug>(Option<T>);

#[test]
fn all_public_types_are_debug() {
IsDebug::<Transient<u32>>(None);
IsDebug::<Singleton<u32>>(None);
IsDebug::<Registry>(None);
IsDebug::<Builder<'static, u32, ()>>(None);
}

0 comments on commit 4da13cb

Please sign in to comment.