@@ -13,7 +13,7 @@ use std::{
1313 cell:: RefCell ,
1414 convert:: { TryFrom as _, TryInto as _} ,
1515 ffi:: { CStr , CString } ,
16- fmt:: { self , Debug , Display , Formatter , Write as _} ,
16+ fmt:: { self , Debug , Formatter , Write as _} ,
1717 mem:: MaybeUninit ,
1818 ops:: { Deref , DerefMut } ,
1919 os:: raw:: { c_uint, c_void} ,
@@ -438,7 +438,8 @@ impl SecretAgentInfo {
438438}
439439
440440/// `SecretAgent` holds the common parts of client and server.
441- #[ derive( Debug ) ]
441+ #[ derive( Debug , derive_more:: Display ) ]
442+ #[ display( "Agent {fd:p}" ) ]
442443#[ expect( clippy:: module_name_repetitions, reason = "This is OK." ) ]
443444pub struct SecretAgent {
444445 fd : * mut prio:: PRFileDesc ,
@@ -1005,14 +1006,9 @@ impl Drop for SecretAgent {
10051006 }
10061007}
10071008
1008- impl Display for SecretAgent {
1009- fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
1010- write ! ( f, "Agent {:p}" , self . fd)
1011- }
1012- }
1013-
1014- #[ derive( PartialOrd , Ord , PartialEq , Eq , Clone ) ]
1009+ #[ derive( PartialOrd , Ord , PartialEq , Eq , Clone , derive_more:: AsRef ) ]
10151010pub struct ResumptionToken {
1011+ #[ as_ref( [ u8 ] ) ]
10161012 token : Vec < u8 > ,
10171013 expiration_time : Instant ,
10181014}
@@ -1026,12 +1022,6 @@ impl Debug for ResumptionToken {
10261022 }
10271023}
10281024
1029- impl AsRef < [ u8 ] > for ResumptionToken {
1030- fn as_ref ( & self ) -> & [ u8 ] {
1031- & self . token
1032- }
1033- }
1034-
10351025impl ResumptionToken {
10361026 #[ must_use]
10371027 pub const fn new ( token : Vec < u8 > , expiration_time : Instant ) -> Self {
@@ -1048,8 +1038,11 @@ impl ResumptionToken {
10481038}
10491039
10501040/// A TLS Client.
1051- #[ derive( Debug ) ]
1041+ #[ derive( Debug , derive_more:: Display , derive_more:: Deref , derive_more:: DerefMut ) ]
1042+ #[ display( "Client {:p}" , "agent.fd" ) ]
10521043pub struct Client {
1044+ #[ deref]
1045+ #[ deref_mut]
10531046 agent : SecretAgent ,
10541047
10551048 /// The name of the server we're attempting a connection to.
@@ -1202,25 +1195,6 @@ impl Client {
12021195 }
12031196}
12041197
1205- impl Deref for Client {
1206- type Target = SecretAgent ;
1207- fn deref ( & self ) -> & SecretAgent {
1208- & self . agent
1209- }
1210- }
1211-
1212- impl DerefMut for Client {
1213- fn deref_mut ( & mut self ) -> & mut SecretAgent {
1214- & mut self . agent
1215- }
1216- }
1217-
1218- impl Display for Client {
1219- fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
1220- write ! ( f, "Client {:p}" , self . agent. fd)
1221- }
1222- }
1223-
12241198/// `ZeroRttCheckResult` encapsulates the options for handling a `ClientHello`.
12251199#[ derive( Clone , Debug , PartialEq , Eq ) ]
12261200pub enum ZeroRttCheckResult {
@@ -1265,8 +1239,11 @@ impl ZeroRttCheckState {
12651239 }
12661240}
12671241
1268- #[ derive( Debug ) ]
1242+ #[ derive( Debug , derive_more:: Display , derive_more:: Deref , derive_more:: DerefMut ) ]
1243+ #[ display( "Server {:p}" , "agent.fd" ) ]
12691244pub struct Server {
1245+ #[ deref]
1246+ #[ deref_mut]
12701247 agent : SecretAgent ,
12711248 /// This holds the HRR callback context.
12721249 zero_rtt_check : Option < Pin < Box < ZeroRttCheckState > > > ,
@@ -1462,25 +1439,6 @@ impl Server {
14621439 }
14631440}
14641441
1465- impl Deref for Server {
1466- type Target = SecretAgent ;
1467- fn deref ( & self ) -> & SecretAgent {
1468- & self . agent
1469- }
1470- }
1471-
1472- impl DerefMut for Server {
1473- fn deref_mut ( & mut self ) -> & mut SecretAgent {
1474- & mut self . agent
1475- }
1476- }
1477-
1478- impl Display for Server {
1479- fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
1480- write ! ( f, "Server {:p}" , self . agent. fd)
1481- }
1482- }
1483-
14841442/// A generic container for Client or Server.
14851443#[ derive( Debug ) ]
14861444pub enum Agent {
0 commit comments