diff --git a/Cargo.lock b/Cargo.lock index f03b689fe..9d5ad08df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2908,7 +2908,6 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" name = "radicle" version = "0.24.0" dependencies = [ - "amplify", "base64 0.21.7", "bytesize", "crossbeam-channel", diff --git a/crates/radicle/Cargo.toml b/crates/radicle/Cargo.toml index a5afce019..03a0d8a33 100644 --- a/crates/radicle/Cargo.toml +++ b/crates/radicle/Cargo.toml @@ -30,7 +30,6 @@ schemars = [ tor = ["cyphernet/tor"] [dependencies] -amplify = { workspace = true, features = ["std"] } base64 = "0.21.3" bytesize = { version = "2", features = ["serde"] } crossbeam-channel = { workspace = true } diff --git a/crates/radicle/src/cob/common.rs b/crates/radicle/src/cob/common.rs index 56356bc06..db9bee1bd 100644 --- a/crates/radicle/src/cob/common.rs +++ b/crates/radicle/src/cob/common.rs @@ -77,8 +77,7 @@ pub enum TitleError { /// - Must not be empty /// - Must not contain `\n` or `\r` characters /// - Will be trimmed of any preceding or following whitespace -#[derive(Display, Deserialize, Serialize, PartialEq, Eq, Clone, Debug)] -#[display(inner)] +#[derive(Deserialize, Serialize, PartialEq, Eq, Clone, Debug)] pub struct Title(String); impl Title { @@ -123,6 +122,12 @@ impl TryFrom for Title { } } +impl std::fmt::Display for Title { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + /// Author. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct Author { diff --git a/crates/radicle/src/cob/patch.rs b/crates/radicle/src/cob/patch.rs index 62f78fcf0..d378e764d 100644 --- a/crates/radicle/src/cob/patch.rs +++ b/crates/radicle/src/cob/patch.rs @@ -12,7 +12,6 @@ use std::ops::Deref; use std::str::FromStr; use std::sync::LazyLock; -use amplify::Wrapper; use nonempty::NonEmpty; use serde::{Deserialize, Serialize}; use storage::{HasRepoId, RepositoryError}; @@ -57,45 +56,89 @@ impl<'a> PatchStream<'a> { } /// Unique identifier for a patch revision. -#[derive( - Wrapper, - Debug, - Clone, - Copy, - Serialize, - Deserialize, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - From, - Display, -)] -#[display(inner)] -#[wrap(Deref)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct RevisionId(EntryId); +impl RevisionId { + pub fn into_inner(self) -> EntryId { + self.0 + } +} + +impl std::fmt::Display for RevisionId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +impl From for RevisionId { + fn from(id: EntryId) -> Self { + Self(id) + } +} + +impl From for EntryId { + fn from(id: RevisionId) -> Self { + id.0 + } +} + +impl Deref for RevisionId { + type Target = EntryId; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl std::borrow::Borrow for RevisionId { + fn borrow(&self) -> &EntryId { + &self.0 + } +} + /// Unique identifier for a patch review. -#[derive( - Wrapper, - Debug, - Clone, - Copy, - Serialize, - Deserialize, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - From, - Display, -)] -#[display(inner)] -#[wrapper(Deref)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ReviewId(EntryId); +impl ReviewId { + pub fn into_inner(self) -> EntryId { + self.0 + } +} + +impl std::fmt::Display for ReviewId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +impl From for ReviewId { + fn from(id: EntryId) -> Self { + Self(id) + } +} + +impl From for EntryId { + fn from(id: ReviewId) -> Self { + id.0 + } +} + +impl Deref for ReviewId { + type Target = EntryId; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl std::borrow::Borrow for ReviewId { + fn borrow(&self) -> &EntryId { + &self.0 + } +} + /// Index of a revision in the revisions list. pub type RevisionIx = usize; diff --git a/crates/radicle/src/cob/patch/cache.rs b/crates/radicle/src/cob/patch/cache.rs index 58532e329..71f390074 100644 --- a/crates/radicle/src/cob/patch/cache.rs +++ b/crates/radicle/src/cob/patch/cache.rs @@ -715,7 +715,6 @@ mod tests { use std::num::NonZeroU8; use std::str::FromStr; - use amplify::Wrapper; use radicle_cob::ObjectId; use crate::cob::cache::{Store, Update, Write}; diff --git a/crates/radicle/src/lib.rs b/crates/radicle/src/lib.rs index c1ee20251..82c69b599 100644 --- a/crates/radicle/src/lib.rs +++ b/crates/radicle/src/lib.rs @@ -3,9 +3,6 @@ pub extern crate radicle_crypto as crypto; -#[macro_use] -extern crate amplify; - extern crate radicle_localtime as localtime; mod canonical; diff --git a/crates/radicle/src/node.rs b/crates/radicle/src/node.rs index f1be1bd82..7503522a8 100644 --- a/crates/radicle/src/node.rs +++ b/crates/radicle/src/node.rs @@ -32,7 +32,6 @@ use std::os::unix::net::UnixStream; #[cfg(windows)] use uds_windows::UnixStream; -use amplify::WrapperMut; use cyphernet::addr::{AddrParseError, NetAddr}; use localtime::{LocalDuration, LocalTime}; use serde::de::DeserializeOwned; @@ -462,9 +461,7 @@ impl TryFrom<&sqlite::Value> for Alias { } /// Peer public protocol address. -#[derive(Clone, Eq, PartialEq, Debug, Hash, Wrapper, WrapperMut, Serialize, Deserialize)] -#[wrapper(Deref)] -#[wrapper_mut(DerefMut)] +#[derive(Clone, Eq, PartialEq, Debug, Hash, Serialize, Deserialize)] #[serde(try_from = "String", into = "String")] #[cfg_attr( feature = "schemars", @@ -482,7 +479,6 @@ impl TryFrom<&sqlite::Value> for Alias { ), ))] pub struct Address { - #[wrap] inner: NetAddr, /// See documentation of [`Address::is_ipv6_without_square_brackets`] for details. @@ -652,6 +648,14 @@ impl FromStr for Address { } } +impl Deref for Address { + type Target = NetAddr; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + impl cyphernet::addr::Host for Address { fn requires_proxy(&self) -> bool { self.inner.requires_proxy() diff --git a/crates/radicle/src/node/config.rs b/crates/radicle/src/node/config.rs index f7335817f..3d7ab9a3c 100644 --- a/crates/radicle/src/node/config.rs +++ b/crates/radicle/src/node/config.rs @@ -255,8 +255,7 @@ pub struct ConnectionLimits { /// Rate limiting uses a token bucket for each peer. The capacity of the bucket /// is defined by [`RateLimit::capacity`], and refill rate of the bucket is /// defined by [`RateLimit::fill_rate`]. -#[derive(Debug, Clone, Copy, Serialize, Deserialize, Display)] -#[display("RateLimit(fill_rate={fill_rate}, capacity={capacity})")] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct RateLimit { @@ -278,6 +277,16 @@ pub struct RateLimit { pub capacity: usize, } +impl std::fmt::Display for RateLimit { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "RateLimit(fill_rate={}, capacity={})", + self.fill_rate, self.capacity + ) + } +} + /// Rate limits for inbound and outbound connections. #[derive(Debug, Clone, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] @@ -699,9 +708,8 @@ impl Config { } } -#[derive(Clone, Copy, Debug, Display, Deserialize, Serialize, From)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[serde(transparent)] -#[display("{0}")] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct LogLevel( #[serde(with = "crate::serde_ext::string")] @@ -718,12 +726,24 @@ impl Default for LogLevel { } } +impl From for LogLevel { + fn from(value: log::Level) -> Self { + Self(value) + } +} + impl From for log::Level { fn from(value: LogLevel) -> Self { value.0 } } +impl std::fmt::Display for LogLevel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + #[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(transparent)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] @@ -778,8 +798,7 @@ impl From for LocalDuration { /// - `From<$name> for $type`, i.e. can convert back into the original type macro_rules! wrapper { ($name:ident, $type:ty, $default:expr_2021 $(, $derive:ty)*) => { - #[derive(Clone, Debug, Deserialize, Display, Serialize, From $(, $derive)*)] - #[display("{0}")] + #[derive(Clone, Debug, Deserialize, Serialize $(, $derive)*)] #[serde(transparent)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct $name($type); @@ -790,11 +809,23 @@ macro_rules! wrapper { } } + impl From<$type> for $name { + fn from(value: $type) -> Self { + Self(value) + } + } + impl From<$name> for $type { fn from(value: $name) -> Self { value.0 } } + + impl std::fmt::Display for $name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } + } }; } wrapper!(Workers, usize, 8, Copy);