aboutsummaryrefslogtreecommitdiff
path: root/src/ptr.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-07-31 20:52:37 +0200
committerHampusM <hampus@hampusmat.com>2023-07-31 20:52:37 +0200
commit343661391c21f535e7b832f3fef05e09a61a0a29 (patch)
treee6b06b2fa2addab0a1aa5ae209e5b8b9cf91cfe4 /src/ptr.rs
parent118651055b7844e04aa5b89023c385e483de305f (diff)
refactor!: remove SomeThreadsafePtrError
BREAKING CHANGE: SomeThreadsafePtrError has been removed and SomePtrError is now used by both the methods of SomePtr and of SomeThreadsafePtr
Diffstat (limited to 'src/ptr.rs')
-rw-r--r--src/ptr.rs22
1 files changed, 12 insertions, 10 deletions
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<Interface> = Box<Interface>;
@@ -26,11 +26,11 @@ pub type FactoryPtr<FactoryInterface> = Rc<FactoryInterface>;
pub type ThreadsafeFactoryPtr<FactoryInterface> = Arc<FactoryInterface>;
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>]<Interface>, [<$enum Error>]>
+ pub fn [<$variant:snake>](self) -> Result<[<$variant Ptr>]<Interface>, $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<Interface> SomePtr<Interface>
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<Interface> SomeThreadsafePtr<Interface>
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")))
);