pub struct Range<T> { /* fields omitted */ }
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.
Create a range from left and right bounds.
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");
Create a range from lower and upper bounds.
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");
Create an ascending range.
use moore_vhdl::ty2::IntegerRange;
let r = IntegerRange::ascending(0, 42);
assert_eq!(format!("{}", r), "0 to 42");
Create a descending range.
use moore_vhdl::ty2::IntegerRange;
let r = IntegerRange::descending(42, 0);
assert_eq!(format!("{}", r), "42 downto 0");
Return the direction of the range.
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);
Return the left bound of the range.
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));
Return the right bound of the range.
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));
Return the lower bound of the range.
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));
Return the upper bound of the range.
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));
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.
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);
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.
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));
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.
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);
Check if a value is within this range.
This function checks if self.lower()
is less than or equal to, and
self.upper()
is larger than or equal to, the given value.
Performs copy-assignment from source
. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
Formats the value using the given formatter. Read more
Converts the given value to a String
. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)