diff --git a/crates/aide/Cargo.toml b/crates/aide/Cargo.toml index 774e06a..10613d7 100644 --- a/crates/aide/Cargo.toml +++ b/crates/aide/Cargo.toml @@ -17,7 +17,6 @@ serde_json = "1" thiserror = "1" tracing = "0" aide-macros = { version = "0.7.0", path = "../aide-macros", optional = true } -derive_more = "0.99.17" bytes = { version = "1", optional = true } http = { version = "1.0.0", optional = true } diff --git a/crates/aide/src/helpers/no_api.rs b/crates/aide/src/helpers/no_api.rs index 1dd934f..900ecbf 100644 --- a/crates/aide/src/helpers/no_api.rs +++ b/crates/aide/src/helpers/no_api.rs @@ -1,9 +1,10 @@ -use derive_more::{AsMut, AsRef, Deref, DerefMut, From}; +use std::ops::{Deref, DerefMut}; + use serde::{Deserialize, Serialize}; use crate::{OperationInput, OperationOutput}; -/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a default empty documentation. +/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a default empty documentation. /// For types that already implement [`OperationInput`] or [`OperationOutput`] it overrides the documentation and hides it. /// ```ignore /// pub async fn my_sqlx_tx_endpoint( @@ -11,23 +12,7 @@ use crate::{OperationInput, OperationOutput}; /// ) -> NoApi> // Hides the API of the return type /// # {} /// ``` -#[derive( - Copy, - Clone, - Debug, - Ord, - PartialOrd, - Eq, - PartialEq, - Hash, - Serialize, - Deserialize, - Deref, - DerefMut, - AsRef, - AsMut, - From, -)] +#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] pub struct NoApi(pub T); impl NoApi { @@ -37,6 +22,38 @@ impl NoApi { } } +impl Deref for NoApi { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for NoApi { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef for NoApi { + fn as_ref(&self) -> &T { + &self.0 + } +} + +impl AsMut for NoApi { + fn as_mut(&mut self) -> &mut T { + &mut self.0 + } +} + +impl From for NoApi { + fn from(value: T) -> Self { + Self(value) + } +} + impl OperationInput for NoApi {} impl OperationOutput for NoApi { diff --git a/crates/aide/src/helpers/use_api.rs b/crates/aide/src/helpers/use_api.rs index a98c447..3b5e954 100644 --- a/crates/aide/src/helpers/use_api.rs +++ b/crates/aide/src/helpers/use_api.rs @@ -1,6 +1,8 @@ -use std::marker::PhantomData; +use std::{ + marker::PhantomData, + ops::{Deref, DerefMut}, +}; -use derive_more::{AsMut, AsRef, Deref, DerefMut}; use serde::{Deserialize, Serialize}; use crate::gen::GenContext; @@ -25,36 +27,8 @@ impl IntoApi for T { /// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with the api documentation of [A]. /// For types that already implement [`OperationInput`] or [`OperationOutput`] it overrides the documentation with the provided one. -#[derive( - Copy, - Clone, - Debug, - Ord, - PartialOrd, - Eq, - PartialEq, - Hash, - Serialize, - Deserialize, - Deref, - DerefMut, - AsRef, - AsMut, -)] -pub struct UseApi( - #[as_ref] - #[as_mut] - #[deref] - #[deref_mut] - pub T, - pub PhantomData, -); - -impl From for UseApi { - fn from(value: T) -> Self { - Self(value, Default::default()) - } -} +#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct UseApi(pub T, pub PhantomData); impl UseApi { /// Unwraps [Self] into its inner type @@ -63,6 +37,38 @@ impl UseApi { } } +impl Deref for UseApi { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for UseApi { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef for UseApi { + fn as_ref(&self) -> &T { + &self.0 + } +} + +impl AsMut for UseApi { + fn as_mut(&mut self) -> &mut T { + &mut self.0 + } +} + +impl From for UseApi { + fn from(value: T) -> Self { + Self(value, Default::default()) + } +} + impl OperationInput for UseApi where A: OperationInput, diff --git a/crates/aide/src/helpers/with_api.rs b/crates/aide/src/helpers/with_api.rs index 6d269b2..cd6952d 100644 --- a/crates/aide/src/helpers/with_api.rs +++ b/crates/aide/src/helpers/with_api.rs @@ -1,6 +1,8 @@ -use std::marker::PhantomData; +use std::{ + marker::PhantomData, + ops::{Deref, DerefMut}, +}; -use derive_more::{AsMut, AsRef, Deref, DerefMut}; use serde::{Deserialize, Serialize}; use crate::gen::GenContext; @@ -62,33 +64,11 @@ pub trait ApiOverride { type Target; } -/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a provided documentation. +/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a provided documentation. /// For types that already implement [`OperationInput`] or [`OperationOutput`] it overrides the documentation with the provided one. /// See [`ApiOverride`] on how to implement such an override -#[derive( - Copy, - Clone, - Debug, - Ord, - PartialOrd, - Eq, - PartialEq, - Hash, - Serialize, - Deserialize, - Deref, - DerefMut, - AsRef, - AsMut, -)] -pub struct WithApi( - #[as_ref] - #[as_mut] - #[deref] - #[deref_mut] - pub T::Target, - pub PhantomData, -) +#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct WithApi(pub T::Target, pub PhantomData) where T: ApiOverride; @@ -102,6 +82,44 @@ where } } +impl Deref for WithApi +where + T: ApiOverride, +{ + type Target = T::Target; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for WithApi +where + T: ApiOverride, +{ + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef for WithApi +where + T: ApiOverride, +{ + fn as_ref(&self) -> &T::Target { + &self.0 + } +} + +impl AsMut for WithApi +where + T: ApiOverride, +{ + fn as_mut(&mut self) -> &mut T::Target { + &mut self.0 + } +} + impl OperationInput for WithApi where T: OperationInput + ApiOverride,