make UIntInRange[Inclusive][Type] castable from/to any UInt<N> and add methods to get bit_width, start, and end
This commit is contained in:
parent
040cefea21
commit
3e5b2f126a
1 changed files with 17 additions and 4 deletions
|
|
@ -304,6 +304,15 @@ macro_rules! define_uint_in_range_type {
|
||||||
$SerdeRange { start, end }.intern_sized(),
|
$SerdeRange { start, end }.intern_sized(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
pub fn bit_width(self) -> usize {
|
||||||
|
self.value.width()
|
||||||
|
}
|
||||||
|
pub fn start(self) -> Start::SizeType {
|
||||||
|
self.range.get().start
|
||||||
|
}
|
||||||
|
pub fn end(self) -> End::SizeType {
|
||||||
|
self.range.get().end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Start: Size, End: Size> fmt::Debug for $UIntInRangeType<Start, End> {
|
impl<Start: Size, End: Size> fmt::Debug for $UIntInRangeType<Start, End> {
|
||||||
|
|
@ -477,18 +486,22 @@ macro_rules! define_uint_in_range_type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Start: Size, End: Size> ExprCastTo<UInt> for $UIntInRangeType<Start, End> {
|
impl<Start: Size, End: Size, Width: Size> ExprCastTo<UIntType<Width>>
|
||||||
fn cast_to(src: Expr<Self>, to_type: UInt) -> Expr<UInt> {
|
for $UIntInRangeType<Start, End>
|
||||||
|
{
|
||||||
|
fn cast_to(src: Expr<Self>, to_type: UIntType<Width>) -> Expr<UIntType<Width>> {
|
||||||
src.cast_to_bits().cast_to(to_type)
|
src.cast_to_bits().cast_to(to_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Start: Size, End: Size> ExprCastTo<$UIntInRangeType<Start, End>> for UInt {
|
impl<Start: Size, End: Size, Width: Size> ExprCastTo<$UIntInRangeType<Start, End>>
|
||||||
|
for UIntType<Width>
|
||||||
|
{
|
||||||
fn cast_to(
|
fn cast_to(
|
||||||
src: Expr<Self>,
|
src: Expr<Self>,
|
||||||
to_type: $UIntInRangeType<Start, End>,
|
to_type: $UIntInRangeType<Start, End>,
|
||||||
) -> Expr<$UIntInRangeType<Start, End>> {
|
) -> Expr<$UIntInRangeType<Start, End>> {
|
||||||
src.cast_bits_to(to_type)
|
src.cast_to(to_type.value).cast_bits_to(to_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue