Fixed wrong formatting of references for SignedHex.

This commit is contained in:
2020-10-24 20:18:38 +01:00
parent 6c29f8e9ca
commit 46e794c1c5

View File

@@ -3,15 +3,22 @@
// Imports
use int_conv::Extended;
use ref_cast::RefCast;
use std::fmt::{self, Formatter, LowerHex};
/// A signed numeric type that uses signed hexadecimal formatting.
#[derive(ref_cast::RefCast)]
#[repr(transparent)]
pub struct SignedHex<T>(pub T);
// All references implement it for their underlying type.
impl<'a, T: LowerHex> LowerHex for SignedHex<&'a T> {
#[allow(clippy::use_self)] // We're using a generic version `SignedHex`, not `Self`
impl<'a, T> LowerHex for SignedHex<&'a T>
where
SignedHex<T>: LowerHex,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
<T as LowerHex>::fmt(self.0, f)
<SignedHex<T> as LowerHex>::fmt(SignedHex::<T>::ref_cast(self.0), f)
}
}