Struct moore_vhdl::ty2::Range
source · [−]pub struct Range<T> { /* private fields */ }
Expand description
A directed range of values.
Range<T>
has the same semantics as ranges in VHDL. They have a direction
associated with them, and left and right bounds. The range may be a null
range if the lower bound is greater than or equal to the upper bound.
Implementations
sourceimpl<T: PartialOrd + One> Range<T> where
for<'a> &'a T: Add<Output = T> + Sub<Output = T>,
impl<T: PartialOrd + One> Range<T> where
for<'a> &'a T: Add<Output = T> + Sub<Output = T>,
sourcepub fn with_left_right<D, L, R>(dir: D, left: L, right: R) -> Range<T> where
RangeDir: From<D>,
T: From<L> + From<R>,
pub fn with_left_right<D, L, R>(dir: D, left: L, right: R) -> Range<T> where
RangeDir: From<D>,
T: From<L> + From<R>,
Create a range from left and right bounds.
Example
use moore_vhdl::ty2::{IntegerRange, RangeDir};
let a = IntegerRange::with_left_right(RangeDir::To, 0, 42);
let b = IntegerRange::with_left_right(RangeDir::Downto, 42, 0);
assert_eq!(format!("{}", a), "0 to 42");
assert_eq!(format!("{}", b), "42 downto 0");
sourcepub fn with_lower_upper<D, L, U>(dir: D, lower: L, upper: U) -> Range<T> where
RangeDir: From<D>,
T: From<L> + From<U>,
pub fn with_lower_upper<D, L, U>(dir: D, lower: L, upper: U) -> Range<T> where
RangeDir: From<D>,
T: From<L> + From<U>,
Create a range from lower and upper bounds.
Example
use moore_vhdl::ty2::{IntegerRange, RangeDir};
let a = IntegerRange::with_lower_upper(RangeDir::To, 0, 42);
let b = IntegerRange::with_lower_upper(RangeDir::Downto, 0, 42);
assert_eq!(format!("{}", a), "0 to 42");
assert_eq!(format!("{}", b), "42 downto 0");
sourcepub fn ascending<L, R>(left: L, right: R) -> Range<T> where
T: From<L> + From<R>,
pub fn ascending<L, R>(left: L, right: R) -> Range<T> where
T: From<L> + From<R>,
Create an ascending range.
Example
use moore_vhdl::ty2::IntegerRange;
let r = IntegerRange::ascending(0, 42);
assert_eq!(format!("{}", r), "0 to 42");
sourcepub fn descending<L, R>(left: L, right: R) -> Range<T> where
T: From<L> + From<R>,
pub fn descending<L, R>(left: L, right: R) -> Range<T> where
T: From<L> + From<R>,
Create a descending range.
Example
use moore_vhdl::ty2::IntegerRange;
let r = IntegerRange::descending(42, 0);
assert_eq!(format!("{}", r), "42 downto 0");
sourcepub fn dir(&self) -> RangeDir
pub fn dir(&self) -> RangeDir
Return the direction of the range.
Example
use moore_vhdl::ty2::{IntegerRange, RangeDir};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::descending(42, 0);
assert_eq!(a.dir(), RangeDir::To);
assert_eq!(b.dir(), RangeDir::Downto);
sourcepub fn left(&self) -> &T
pub fn left(&self) -> &T
Return the left bound of the range.
Example
use moore_vhdl::ty2::{IntegerRange, BigInt};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::descending(42, 0);
assert_eq!(a.left(), &BigInt::from(0));
assert_eq!(b.left(), &BigInt::from(42));
sourcepub fn right(&self) -> &T
pub fn right(&self) -> &T
Return the right bound of the range.
Example
use moore_vhdl::ty2::{IntegerRange, BigInt};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::descending(42, 0);
assert_eq!(a.right(), &BigInt::from(42));
assert_eq!(b.right(), &BigInt::from(0));
sourcepub fn lower(&self) -> &T
pub fn lower(&self) -> &T
Return the lower bound of the range.
Example
use moore_vhdl::ty2::{IntegerRange, BigInt};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::descending(42, 0);
assert_eq!(a.lower(), &BigInt::from(0));
assert_eq!(b.lower(), &BigInt::from(0));
sourcepub fn upper(&self) -> &T
pub fn upper(&self) -> &T
Return the upper bound of the range.
Example
use moore_vhdl::ty2::{IntegerRange, BigInt};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::descending(42, 0);
assert_eq!(a.upper(), &BigInt::from(42));
assert_eq!(b.upper(), &BigInt::from(42));
sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Return true if the range is a null range.
A null range has its lower bound greater than or equal to its upper bound, and thus also a length of 0 or lower.
Example
use moore_vhdl::ty2::IntegerRange;
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::ascending(42, 0);
assert_eq!(a.is_null(), false);
assert_eq!(b.is_null(), true);
sourcepub fn len(&self) -> T
pub fn len(&self) -> T
Return the length of the range.
The length of a range is defined as upper + 1 - lower
. The result may
be negative, indicating that the range is a null range.
Example
use moore_vhdl::ty2::{IntegerRange, BigInt};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::ascending(42, 0);
assert_eq!(a.len(), BigInt::from(43));
assert_eq!(b.len(), BigInt::from(-41));
sourcepub fn has_subrange(&self, subrange: &Self) -> bool
pub fn has_subrange(&self, subrange: &Self) -> bool
Check if another range is a subrange of this range.
This function checks if self.lower()
is less than or equal to, and
self.upper()
is larger than or equal to, the corresponding bounds of
the subrange.
Example
use moore_vhdl::ty2::{IntegerRange, BigInt};
let a = IntegerRange::ascending(0, 42);
let b = IntegerRange::ascending(4, 16);
let c = IntegerRange::descending(16, 4);
assert_eq!(a.has_subrange(&b), true);
assert_eq!(a.has_subrange(&c), true);
assert_eq!(b.has_subrange(&a), false);
assert_eq!(c.has_subrange(&a), false);
assert_eq!(b.has_subrange(&c), true);
assert_eq!(c.has_subrange(&b), true);
Trait Implementations
impl<T: Copy> Copy for Range<T>
impl<T: Eq> Eq for Range<T>
impl<T> StructuralEq for Range<T>
impl<T> StructuralPartialEq for Range<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Range<T> where
T: RefUnwindSafe,
impl<T> Send for Range<T> where
T: Send,
impl<T> Sync for Range<T> where
T: Sync,
impl<T> Unpin for Range<T> where
T: Unpin,
impl<T> UnwindSafe for Range<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more