[][src]Struct moore_vhdl::ty2::Range

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.

Methods

impl<T: PartialOrd + One> Range<T> where
    &'a T: Add<Output = T> + Sub<Output = T>, 
[src]

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>, 
[src]

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");

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>, 
[src]

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");

pub fn ascending<L, R>(left: L, right: R) -> Range<T> where
    T: From<L> + From<R>, 
[src]

Create an ascending range.

Example

use moore_vhdl::ty2::IntegerRange;

let r = IntegerRange::ascending(0, 42);

assert_eq!(format!("{}", r), "0 to 42");

pub fn descending<L, R>(left: L, right: R) -> Range<T> where
    T: From<L> + From<R>, 
[src]

Create a descending range.

Example

use moore_vhdl::ty2::IntegerRange;

let r = IntegerRange::descending(42, 0);

assert_eq!(format!("{}", r), "42 downto 0");

pub fn dir(&self) -> RangeDir
[src]

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);

pub fn left(&self) -> &T
[src]

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));

pub fn right(&self) -> &T
[src]

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));

pub fn lower(&self) -> &T
[src]

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));

pub fn upper(&self) -> &T
[src]

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));

pub fn is_null(&self) -> bool
[src]

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);

pub fn len(&self) -> T
[src]

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));

pub fn has_subrange(&self, subrange: &Self) -> bool
[src]

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);

pub fn contains(&self, value: &T) -> bool
[src]

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.

Trait Implementations

impl<T: Eq> Eq for Range<T>
[src]

impl<T: Copy> Copy for Range<T>
[src]

impl<T: Clone> Clone for Range<T>
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: PartialEq> PartialEq<Range<T>> for Range<T>
[src]

impl<T: Debug> Debug for Range<T>
[src]

impl<T: Hash> Hash for Range<T>
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Display> Display for Range<T>
[src]

Auto Trait Implementations

impl<T> Send for Range<T> where
    T: Send

impl<T> Sync for Range<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.