Skip to content

Commit

Permalink
chore: fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandros committed Oct 8, 2024
1 parent 0112b46 commit 336b3aa
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rusty-injector-macros/src/attr_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::similar_names, clippy::assertions_on_result_states)]
use quote::{format_ident, quote};
use quote::format_ident;

use super::*;

Expand Down
10 changes: 6 additions & 4 deletions rusty-injector-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#![allow(clippy::panic)]
#![allow(clippy::panic, clippy::module_name_repetitions)]

use darling::FromDeriveInput;
use quote::{format_ident, quote};
use syn::punctuated::Punctuated;
use syn::token::Comma;
use syn::{parse_macro_input, Data, DeriveInput, Field, Fields, Type};
use syn::{parse_macro_input, Data, DeriveInput, Field, Fields};

use self::attr::DeriveAttrInput;

mod attr;

/// # Panics
/// TODO
#[proc_macro_derive(Inject, attributes(provides, inject))]
pub fn derive_inject(
input: proc_macro::TokenStream,
Expand Down Expand Up @@ -141,8 +143,7 @@ fn get_fields_from_struct(data: &Data) -> (bool, Punctuated<Field, Comma>) {
Fields::Unnamed(ref unnamed) => (false, unnamed.unnamed.clone()),
Fields::Unit => panic!("structs must be constructible"),
},
Data::Enum(_) => panic!("not supported"),
Data::Union(_) => panic!("not supported"),
Data::Enum(_) | Data::Union(_) => panic!("not supported"),
}
}

Expand All @@ -157,6 +158,7 @@ fn get_fields_from_struct(data: &Data) -> (bool, Punctuated<Field, Comma>) {
// Type::Never(_) => false,
// Type::Paren(_) => false,
// Type::Path(path) => {
// // Let else not stabilized on 1.64.0. TODO: Replace.
// let Some(first_segement) = path.path.segments.get(0) else {
// return false;
// };
Expand Down
1 change: 1 addition & 0 deletions rusty-injector-macros/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::module_name_repetitions)]
//! Integration tests.
// Common code across all tests.
Expand Down
2 changes: 2 additions & 0 deletions rusty-injector/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Transient<T> {
}

impl<T: Send + Sync + 'static> Transient<T> {
#[must_use]
pub fn get(self) -> T {
self.inner
}
Expand All @@ -36,6 +37,7 @@ pub struct Singleton<T> {
}

impl<T: Send + Sync + 'static> Singleton<T> {
#[must_use]
pub fn get(self) -> Arc<T> {
self.inner
}
Expand Down
2 changes: 2 additions & 0 deletions rusty-injector/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::module_name_repetitions)]

use thiserror::Error;

#[derive(Debug, Error)]
Expand Down
16 changes: 15 additions & 1 deletion rusty-injector/src/lazy_transient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
{
fn default() -> Self {
Self {
inner: Default::default(),
inner: RwLock::default(),
}
}
}
Expand All @@ -24,10 +24,16 @@ impl<T> LazyTransient<T>
where
T: Send + Sync + 'static,
{
/// # Panics
/// TODO
#[must_use]
pub fn resolved() -> Self {
Self::resolved_with(Registry::global())
}

/// # Panics
/// TODO
#[must_use]
pub fn resolved_with(registry: &Registry) -> Self {
registry
.get_transient::<T>()
Expand All @@ -37,10 +43,14 @@ where
.expect("dependency or transient not registered")
}

/// # Errors
/// TODO
pub fn resolve(&self) -> Result<(), ResolveError> {
self.resolve_with(Registry::global())
}

/// # Errors
/// TODO
pub fn resolve_with(
&self,
registry: &Registry,
Expand All @@ -59,6 +69,8 @@ where
}
}

/// # Panics
/// TODO
pub fn get(&self) -> MappedRwLockReadGuard<'_, T> {
if self.inner.read().is_none() {
self.resolve().expect("Deref for LazyTransient<T>");
Expand All @@ -71,6 +83,8 @@ where
})
}

/// # Panics
/// TODO
pub fn get_mut(&mut self) -> MappedRwLockWriteGuard<'_, T> {
if self.inner.read().is_none() {
self.resolve().expect("Deref for LazyTransient<T>");
Expand Down
3 changes: 3 additions & 0 deletions rusty-injector/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct Registry {
}

impl Registry {
#[must_use]
pub fn empty() -> Self {
Self {
objects: RwLock::new(HashMap::new()),
Expand Down Expand Up @@ -134,6 +135,8 @@ impl Registry {
})
}

/// # Safety
/// Ensure that no other thread is currently using [`Registry::global()`].
pub unsafe fn reset_global() {
let registry = Self::global();
{
Expand Down

0 comments on commit 336b3aa

Please sign in to comment.