formatters for address type
This commit is contained in:
parent
cd7a686e0d
commit
431e3a1fca
1 changed files with 28 additions and 1 deletions
|
@ -1,4 +1,7 @@
|
||||||
use std::ops::{Add, Sub};
|
use std::{
|
||||||
|
fmt::{Binary, Display, LowerHex, UpperHex},
|
||||||
|
ops::{Add, Sub},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum AddressError {
|
pub(crate) enum AddressError {
|
||||||
|
@ -8,6 +11,30 @@ pub(crate) enum AddressError {
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub(crate) struct BoundedAddress<const MIN: u16, const MAX: u16>(u16);
|
pub(crate) struct BoundedAddress<const MIN: u16, const MAX: u16>(u16);
|
||||||
|
|
||||||
|
impl<const MIN: u16, const MAX: u16> Display for BoundedAddress<MIN, MAX> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const MIN: u16, const MAX: u16> LowerHex for BoundedAddress<MIN, MAX> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
LowerHex::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const MIN: u16, const MAX: u16> UpperHex for BoundedAddress<MIN, MAX> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
UpperHex::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const MIN: u16, const MAX: u16> Binary for BoundedAddress<MIN, MAX> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
Binary::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<const MIN: u16, const MAX: u16> Add<u16> for BoundedAddress<MIN, MAX> {
|
impl<const MIN: u16, const MAX: u16> Add<u16> for BoundedAddress<MIN, MAX> {
|
||||||
type Output = Option<BoundedAddress<MIN, MAX>>;
|
type Output = Option<BoundedAddress<MIN, MAX>>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue