Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Implement Debug for some structures #3941

Merged
merged 3 commits into from
Nov 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl From<multiaddr::Error> for ParseErr {
}

/// Network service configuration.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct NetworkConfiguration {
/// Directory path to store general network configuration. None means nothing will be saved.
pub config_path: Option<String>,
Expand Down Expand Up @@ -317,7 +317,7 @@ impl NetworkConfiguration {
}

/// Configuration for the transport layer.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum TransportConfig {
/// Normal transport mode.
Normal {
Expand Down Expand Up @@ -362,7 +362,7 @@ impl NonReservedPeerMode {
/// The configuration of a node's secret key, describing the type of key
/// and how it is obtained. A node's identity keypair is the result of
/// the evaluation of the node key configuration.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum NodeKeyConfig {
/// A Ed25519 secret key configuration.
Ed25519(Secret<ed25519::SecretKey>)
Expand All @@ -372,7 +372,7 @@ pub enum NodeKeyConfig {
pub type Ed25519Secret = Secret<ed25519::SecretKey>;

/// The configuration options for obtaining a secret key `K`.
#[derive(Clone)]
#[derive(Clone, Debug)]
Copy link
Contributor

@tomaka tomaka Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a manual implementation of Debug here that doesn't print the value of K.

Something like:

impl<K> fmt::Debug for Secret<K> {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		match self {
			Secret::Input(_) => f.debug_tuple("Secret::Input").finish(),
			Secret::File(path) => f.debug_tuple("Secret::File").field(path).finish(),
			Secret::New => f.debug_tuple("Secret::New").finish(),
		}
	}
}

In practice I think that we never use anything like Secret<Vec<u8>>, but I think we're never careful enough when it comes to this. Someone might actually use Secret<Vec<u8>> in the future and not think about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Turns out that this suggestions is pretty good already so I simply copied and pasted

pub enum Secret<K> {
/// Use the given secret key `K`.
Input(K),
Expand Down