1use core::fmt;
2
3pub mod map;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub struct MemoryRange
7{
8	first: u32,
9	last: u32,
10}
11
12impl MemoryRange
13{
14	pub const MIN: Self = MemoryRange{first: 0, last: 0};
15	pub const MAX: Self = MemoryRange{first: u32::MAX, last: u32::MAX};
16	pub const ALL: Self = MemoryRange{first: 0, last: u32::MAX};
17	
18	pub fn new(first: u32, last: u32) -> Self
19	{
20		if first > last {panic!("invalid range {first} -> {last}");}
21		Self{first, last}
22	}
23	
24	pub fn get_first(&self) -> u32
25	{
26		self.first
27	}
28	
29	pub fn get_last(&self) -> u32
30	{
31		self.last
32	}
33}
34
35macro_rules!mem_fmt
36{
37	($name:ident) =>
38	{
39		impl fmt::$name for MemoryRange
40		{
41			fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
42			{
43				<u32 as fmt::$name>::fmt(&self.first, f)?;
44				f.write_str(" -> ")?;
45				<u32 as fmt::$name>::fmt(&self.last, f)
46			}
47		}
48	};
49}
50mem_fmt!(Display);
51mem_fmt!(UpperHex);
52mem_fmt!(LowerHex);
53mem_fmt!(Octal);
54mem_fmt!(Binary);