Skip to content
Merged
Changes from 2 commits
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
38 changes: 26 additions & 12 deletions primitives/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,30 @@ impl OperatingMode for MessagesOperatingMode {

/// Lane id which implements `TypeId`.
#[derive(
Clone,
Copy,
Decode,
Default,
Encode,
Eq,
Ord,
PartialOrd,
PartialEq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
Clone, Copy, Decode, Default, Encode, Eq, Ord, PartialOrd, PartialEq, TypeInfo, MaxEncodedLen,
)]
pub struct LaneId(pub [u8; 4]);

pub use lane_id_debug_impl::*;

#[cfg(not(feature = "std"))]
mod lane_id_debug_impl {
impl core::fmt::Debug for super::LaneId {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
fmt.write_str("<stripped>")
}
}
}

#[cfg(feature = "std")]
mod lane_id_debug_impl {
impl std::fmt::Debug for super::LaneId {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(fmt)
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we want to print <stripped> for non-std environments ? Was this the previous behaviour ?

Could we just do the following ?

impl core::fmt::Debug for LaneId {
	fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
		self.0.fmt(fmt)
	}
}

Would this work for both std and non-std environments ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, "" is how RuntimeDebug works. I think you're right and in previous version, it was printing the same from the no-std env too, because we weren't using some custom type. Let's change it

impl AsRef<[u8]> for LaneId {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down Expand Up @@ -458,4 +467,9 @@ mod tests {
assert!(delivered_messages.contains_message(150));
assert!(!delivered_messages.contains_message(151));
}

#[test]
fn lane_id_debug_format_works_as_before() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: I would rename this to something like: lane_id_debug_prints_short_string

assert_eq!(format!("{:?}", LaneId([0, 0, 0, 0])), format!("{:?}", [0, 0, 0, 0]),);
}
}