From 343661391c21f535e7b832f3fef05e09a61a0a29 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 31 Jul 2023 20:52:37 +0200 Subject: refactor!: remove SomeThreadsafePtrError BREAKING CHANGE: SomeThreadsafePtrError has been removed and SomePtrError is now used by both the methods of SomePtr and of SomeThreadsafePtr --- src/ptr.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/ptr.rs') diff --git a/src/ptr.rs b/src/ptr.rs index 46418d1..bcaa566 100644 --- a/src/ptr.rs +++ b/src/ptr.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use paste::paste; -use crate::errors::ptr::{SomePtrError, SomeThreadsafePtrError}; +use crate::errors::ptr::SomePtrError; /// A smart pointer for a interface in the transient scope. pub type TransientPtr = Box; @@ -26,11 +26,11 @@ pub type FactoryPtr = Rc; pub type ThreadsafeFactoryPtr = Arc; macro_rules! create_as_variant_fn { - ($enum: ident, $variant: ident) => { - create_as_variant_fn!($enum, $variant,); + ($enum: ident, $variant: ident, $err: ident) => { + create_as_variant_fn!($enum, $variant, $err,); }; - ($enum: ident, $variant: ident, $($attrs: meta),*) => { + ($enum: ident, $variant: ident, $err: ident, $($attrs: meta),*) => { paste! { #[doc = "Returns as the `" [<$variant>] "` variant.\n" @@ -39,13 +39,13 @@ macro_rules! create_as_variant_fn { "Will return Err if it's not the `" [<$variant>] "` variant." ] $(#[$attrs])* - pub fn [<$variant:snake>](self) -> Result<[<$variant Ptr>], [<$enum Error>]> + pub fn [<$variant:snake>](self) -> Result<[<$variant Ptr>], $err> { if let $enum::$variant(ptr) = self { return Ok(ptr); } - Err([<$enum Error>]::WrongPtrType { + Err($err::WrongPtrType { expected: stringify!($variant), found: self.into() }) @@ -76,13 +76,14 @@ impl SomePtr where Interface: 'static + ?Sized, { - create_as_variant_fn!(SomePtr, Transient); + create_as_variant_fn!(SomePtr, Transient, SomePtrError); - create_as_variant_fn!(SomePtr, Singleton); + create_as_variant_fn!(SomePtr, Singleton, SomePtrError); create_as_variant_fn!( SomePtr, Factory, + SomePtrError, cfg(feature = "factory"), cfg_attr(doc_cfg, doc(cfg(feature = "factory"))) ); @@ -110,13 +111,14 @@ impl SomeThreadsafePtr where Interface: 'static + ?Sized, { - create_as_variant_fn!(SomeThreadsafePtr, Transient); + create_as_variant_fn!(SomeThreadsafePtr, Transient, SomePtrError); - create_as_variant_fn!(SomeThreadsafePtr, ThreadsafeSingleton); + create_as_variant_fn!(SomeThreadsafePtr, ThreadsafeSingleton, SomePtrError); create_as_variant_fn!( SomeThreadsafePtr, ThreadsafeFactory, + SomePtrError, cfg(feature = "factory"), cfg_attr(doc_cfg, doc(cfg(feature = "factory"))) ); -- cgit v1.2.3-18-g5258