Skip to content

Commit

Permalink
code: Update to derive_more 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Aug 25, 2024
1 parent f12c830 commit 6d8a9c8
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 186 deletions.
345 changes: 205 additions & 140 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ color-eyre = "0.6.0"
console = "0.15.0"
crypto_secretbox = "0.1.1"
ctrlc = "3.2.1"
derive_more = { version = "0.99.0", default-features = false }
derive_more = { version = "1.0", default-features = false }
dialoguer = "0.11"
env_logger = "0.11"
eyre = "0.6.5"
Expand Down
10 changes: 5 additions & 5 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ impl AsRef<str> for AppID {
PartialEq, Eq, Clone, Debug, Deserialize, Serialize, derive_more::Display, derive_more::Deref,
)]
#[serde(transparent)]
#[display(fmt = "MySide({})", "&*_0")]
#[display("MySide({})", "&*_0")]
#[deprecated(
since = "0.7.0",
note = "This will be a private type in the future. Open an issue if you require access to protocol intrinsics in the future"
Expand Down Expand Up @@ -667,7 +667,7 @@ impl MySide {
PartialEq, Eq, Clone, Debug, Deserialize, Serialize, derive_more::Display, derive_more::Deref,
)]
#[serde(transparent)]
#[display(fmt = "TheirSide({})", "&*_0")]
#[display("TheirSide({})", "&*_0")]
#[deprecated(
since = "0.7.0",
note = "This will be a private type in the future. Open an issue if you require access to protocol intrinsics in the future"
Expand All @@ -685,7 +685,7 @@ impl<S: Into<String>> From<S> for TheirSide {
)]
#[serde(transparent)]
#[deref(forward)]
#[display(fmt = "{}", "&*_0")]
#[display("{}", "&*_0")]
#[deprecated(
since = "0.7.0",
note = "This will be a private type in the future. Open an issue if you require access to protocol intrinsics in the future"
Expand Down Expand Up @@ -750,7 +750,7 @@ pub struct Mailbox(pub String);
)]
#[serde(transparent)]
#[deref(forward)]
#[display(fmt = "{}", _0)]
#[display("{}", _0)]
pub struct Nameplate(
#[deprecated(since = "0.7.0", note = "use the AsRef<str> implementation")] pub String,
);
Expand Down Expand Up @@ -791,7 +791,7 @@ impl AsRef<str> for Nameplate {
* a wordlist is a common convention.
*/
#[derive(PartialEq, Eq, Clone, Debug, derive_more::Display, derive_more::Deref)]
#[display(fmt = "{}", _0)]
#[display("{}", _0)]
pub struct Code(
#[deprecated(since = "0.7.0", note = "use the AsRef<str> implementation")] pub String,
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl KeyPurpose for GenericKey {}
* You don't need to do any crypto, but you might need it to derive subkeys for sub-protocols.
*/
#[derive(Debug, Clone, derive_more::Display, derive_more::Deref)]
#[display(fmt = "{:?}", _0)]
#[display("{:?}", _0)]
#[deref(forward)]
pub struct Key<P: KeyPurpose>(
#[deref]
Expand Down
4 changes: 2 additions & 2 deletions src/core/rendezvous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl RendezvousError {
type MessageQueue = VecDeque<EncryptedMessage>;

#[derive(Clone, Debug, derive_more::Display)]
#[display(fmt = "{:?}", _0)]
#[display("{:?}", _0)]
struct NameplateList(Vec<Nameplate>);

#[cfg(not(target_family = "wasm"))]
Expand Down Expand Up @@ -289,7 +289,7 @@ enum RendezvousReply {

#[derive(Clone, Debug, derive_more::Display)]
#[display(
fmt = "MailboxMachine {{ mailbox: {}, processed: [{}] }}",
"MailboxMachine {{ mailbox: {}, processed: [{}] }}",
mailbox,
"processed.iter().map(|p| format!(\"{}\", p)).collect::<Vec<String>>().join(\", \")"
)]
Expand Down
40 changes: 18 additions & 22 deletions src/core/server_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Nameplate_ {
#[serde(rename_all = "kebab-case")]
#[serde(tag = "method")]
pub enum SubmitPermission {
#[display(fmt = "Hashcash {{ stamp: '{}' }}", stamp)]
#[display("Hashcash {{ stamp: '{}' }}", stamp)]
Hashcash { stamp: String },
}

Expand Down Expand Up @@ -95,11 +95,7 @@ impl std::fmt::Display for PermissionRequired {
}

#[derive(Deserialize, Debug, PartialEq, Eq, derive_more::Display)]
#[display(
fmt = "HashcashPermission {{ bits: {}, resource: '{}' }}",
bits,
resource
)]
#[display("HashcashPermission {{ bits: {}, resource: '{}' }}", bits, resource)]
#[serde(deny_unknown_fields)]
pub struct HashcashPermission {
pub bits: u32,
Expand All @@ -108,7 +104,7 @@ pub struct HashcashPermission {

#[derive(Debug, PartialEq, Clone, Deserialize, derive_more::Display)]
#[display(
fmt = "EncryptedMessage {{ side: {}, phase: {}, body: {}",
"EncryptedMessage {{ side: {}, phase: {}, body: {}",
side,
phase,
"crate::util::DisplayBytes(body)"
Expand All @@ -134,29 +130,29 @@ impl EncryptedMessage {
#[serde(tag = "type")]
#[allow(dead_code)]
pub enum OutboundMessage {
#[display(fmt = "SubmitPermission({})", _0)]
#[display("SubmitPermission({})", _0)]
SubmitPermission(SubmitPermission),
#[display(fmt = "Bind {{ appid: {}, side: {} }}", appid, side)]
#[display("Bind {{ appid: {}, side: {} }}", appid, side)]
Bind {
appid: AppID,
side: MySide,
},
List,
Allocate,
#[display(fmt = "Claim({})", nameplate)]
#[display("Claim({})", nameplate)]
Claim {
nameplate: String,
},
#[display(fmt = "Release({})", nameplate)]
#[display("Release({})", nameplate)]
Release {
nameplate: String,
}, // TODO: nominally optional
#[display(fmt = "Open({})", mailbox)]
#[display("Open({})", mailbox)]
Open {
mailbox: Mailbox,
},
#[display(
fmt = "Add {{ phase: {}, body: {} }}",
"Add {{ phase: {}, body: {} }}",
phase,
"crate::util::DisplayBytes(body)"
)]
Expand All @@ -165,12 +161,12 @@ pub enum OutboundMessage {
#[serde(serialize_with = "hex::serde::serialize")]
body: Vec<u8>,
},
#[display(fmt = "Close {{ mailbox: {}, mood: {} }}", mailbox, mood)]
#[display("Close {{ mailbox: {}, mood: {} }}", mailbox, mood)]
Close {
mailbox: Mailbox,
mood: Mood,
},
#[display(fmt = "Ping({})", ping)]
#[display("Ping({})", ping)]
Ping {
ping: u64,
},
Expand Down Expand Up @@ -212,38 +208,38 @@ impl OutboundMessage {
#[serde(rename_all = "kebab-case")]
#[serde(tag = "type")]
pub enum InboundMessage {
#[display(fmt = "Welcome({})", welcome)]
#[display("Welcome({})", welcome)]
Welcome {
welcome: WelcomeMessage,
},
#[display(fmt = "Nameplates({:?})", nameplates)]
#[display("Nameplates({:?})", nameplates)]
Nameplates {
#[serde(with = "Nameplate_")]
nameplates: Vec<Nameplate>,
},
#[display(fmt = "Allocated({})", nameplate)]
#[display("Allocated({})", nameplate)]
Allocated {
nameplate: Nameplate,
},
#[display(fmt = "Claimed({})", mailbox)]
#[display("Claimed({})", mailbox)]
Claimed {
mailbox: Mailbox,
},
Released,
#[display(
fmt = "Message {{ side: {}, phase: {:?}, body: {} }}",
"Message {{ side: {}, phase: {:?}, body: {} }}",
_0.side,
_0.phase,
"crate::util::DisplayBytes(_0.body.as_bytes())"
)]
Message(EncryptedMessage),
Closed,
Ack,
#[display(fmt = "Pong({})", pong)]
#[display("Pong({})", pong)]
Pong {
pong: u64,
},
#[display(fmt = "Error {{ error: {:?}, .. }}", error)]
#[display("Error {{ error: {:?}, .. }}", error)]
Error {
error: String,
/// A copy of the original message that caused the error.
Expand Down
12 changes: 6 additions & 6 deletions src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,28 +244,28 @@ impl Default for AppVersionTransferV2Hint {
pub enum PeerMessage {
/* V1 */
/// A transit message
#[display(fmt = "transit")]
#[display("transit")]
Transit(v1::TransitV1),

/// An offer message
#[display(fmt = "offer")]
#[display("offer")]
Offer(v1::OfferMessage),

/// An answer message
#[display(fmt = "answer")]
#[display("answer")]
Answer(v1::AnswerMessage),
/* V2 */
/// A transit v2 message
#[cfg(feature = "experimental-transfer-v2")]
#[display(fmt = "transit-v2")]
#[display("transit-v2")]
TransitV2(v2::TransitV2),

/// Tell the other side you got an error
#[display(fmt = "error")]
#[display("error")]
Error(String),

/// An unknown message
#[display(fmt = "unknown")]
#[display("unknown")]
#[serde(other)]
Unknown,
}
Expand Down
16 changes: 8 additions & 8 deletions src/transfer/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ pub struct TransitV2 {
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum PeerMessageV2 {
#[display(fmt = "offer")]
#[display("offer")]
Offer(Offer),
#[display(fmt = "answer")]
#[display("answer")]
Answer(AnswerMessage),
#[display(fmt = "file-start")]
#[display("file-start")]
FileStart(FileStart),
#[display(fmt = "payload")]
#[display("payload")]
Payload(Payload),
#[display(fmt = "file-end")]
#[display("file-end")]
FileEnd(FileEnd),
#[display(fmt = "transfer-ack")]
#[display("transfer-ack")]
TransferAck(TransferAck),
#[display(fmt = "error")]
#[display("error")]
Error(String),
#[display(fmt = "unknown")]
#[display("unknown")]
#[serde(other)]
Unknown,
}
Expand Down
2 changes: 1 addition & 1 deletion src/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl serde::Serialize for Hints {

/** hostname and port for direct connection */
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash, derive_more::Display)]
#[display(fmt = "tcp://{}:{}", hostname, port)]
#[display("tcp://{}:{}", hostname, port)]
pub struct DirectHint {
// DirectHint also contains a `priority` field, but it is underspecified
// and we won't use it
Expand Down

0 comments on commit 6d8a9c8

Please sign in to comment.