Use derive_more to derive AsRef.

This commit is contained in:
Nick Mathewson 2022-03-29 15:16:35 -04:00
parent 5233d35223
commit df3c51c8a0
3 changed files with 5 additions and 12 deletions

1
Cargo.lock generated
View File

@ -3399,6 +3399,7 @@ name = "tor-guardmgr"
version = "0.1.0"
dependencies = [
"derive_builder",
"derive_more",
"educe",
"futures",
"humantime-serde",

View File

@ -30,6 +30,7 @@ tor-rtcompat = { path = "../tor-rtcompat", version = "0.1.0" }
tor-units = { path = "../tor-units", version = "0.1.0" }
derive_builder = "0.11"
derive_more = "0.99"
educe = "0.4.6"
futures = "0.3.14"
humantime-serde = "1.1.1"

View File

@ -1,5 +1,6 @@
//! Identifier objects used to specify guards and/or fallbacks.
use derive_more::AsRef;
use serde::{Deserialize, Serialize};
use tor_llcrypto::pk;
@ -16,7 +17,7 @@ pub(crate) struct IdPair {
///
/// This is a separate type from GuardId and FirstHopId to avoid confusion
/// about what kind of object we're identifying.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, AsRef)]
pub(crate) struct FallbackId(pub(crate) IdPair);
impl FallbackId {
@ -29,17 +30,12 @@ impl FallbackId {
Self::new(*target.ed_identity(), *target.rsa_identity())
}
}
impl AsRef<IdPair> for FallbackId {
fn as_ref(&self) -> &IdPair {
&self.0
}
}
/// An identifier for a sampled guard.
///
/// This is a separate type from GuardId and FirstHopId to avoid confusion
/// about what kind of object we're identifying.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Hash, Ord, PartialOrd)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Hash, Ord, PartialOrd, AsRef)]
#[serde(transparent)]
pub(crate) struct GuardId(pub(crate) IdPair);
@ -53,11 +49,6 @@ impl GuardId {
Self::new(*target.ed_identity(), *target.rsa_identity())
}
}
impl AsRef<IdPair> for GuardId {
fn as_ref(&self) -> &IdPair {
&self.0
}
}
/// Implementation type held inside of FirstHopId.
///