Struct moore_vhdl::ty2::PhysicalBasetype
source · [−]pub struct PhysicalBasetype { /* private fields */ }
Expand description
A physical base type.
In VHDL a physical type is an integer multiple of some measurement unit. A physical type has exactly one primary unit, and multiple secondary units defined as multiples of that primary unit.
Implementations
sourceimpl PhysicalBasetype
impl PhysicalBasetype
sourcepub fn new<I>(
range: Range<BigInt>,
units: I,
primary: usize
) -> PhysicalBasetype where
I: IntoIterator<Item = PhysicalUnit>,
pub fn new<I>(
range: Range<BigInt>,
units: I,
primary: usize
) -> PhysicalBasetype where
I: IntoIterator<Item = PhysicalUnit>,
Create a new physical type.
Example
use moore_vhdl::ty2::{PhysicalBasetype, PhysicalUnit, Range};
use moore_common::name::get_name_table;
let ty = PhysicalBasetype::new(Range::ascending(0, 1_000_000), vec![
PhysicalUnit::primary(get_name_table().intern("fs", false), 1),
PhysicalUnit::secondary(get_name_table().intern("ps", false), 1_000, 1000, 0),
PhysicalUnit::secondary(get_name_table().intern("ns", false), 1_000_000, 1000, 1),
], 0);
assert_eq!(format!("{}", ty), "0 to 1000000 units (fs, ps, ns)");
Methods from Deref<Target = Range<BigInt>>
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
sourceimpl<'a, 't> Alloc<'a, 'a, PhysicalBasetype> for TypeArena<'t> where
't: 'a,
impl<'a, 't> Alloc<'a, 'a, PhysicalBasetype> for TypeArena<'t> where
't: 'a,
sourcefn alloc(&'a self, value: PhysicalBasetype) -> &'a mut PhysicalBasetype
fn alloc(&'a self, value: PhysicalBasetype) -> &'a mut PhysicalBasetype
Allocate a value of type T
.
sourceimpl Clone for PhysicalBasetype
impl Clone for PhysicalBasetype
sourcefn clone(&self) -> PhysicalBasetype
fn clone(&self) -> PhysicalBasetype
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for PhysicalBasetype
impl Debug for PhysicalBasetype
sourceimpl Deref for PhysicalBasetype
impl Deref for PhysicalBasetype
sourceimpl Display for PhysicalBasetype
impl Display for PhysicalBasetype
sourceimpl PartialEq<PhysicalBasetype> for PhysicalBasetype
impl PartialEq<PhysicalBasetype> for PhysicalBasetype
sourcefn eq(&self, other: &PhysicalBasetype) -> bool
fn eq(&self, other: &PhysicalBasetype) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PhysicalBasetype) -> bool
fn ne(&self, other: &PhysicalBasetype) -> bool
This method tests for !=
.
sourceimpl PhysicalType for PhysicalBasetype
impl PhysicalType for PhysicalBasetype
sourcefn units(&self) -> &[PhysicalUnit]
fn units(&self) -> &[PhysicalUnit]
The units of measure of this type.
sourcefn primary_index(&self) -> usize
fn primary_index(&self) -> usize
The index of the primary unit.
sourcefn as_basetype(&self) -> Option<&PhysicalBasetype>
fn as_basetype(&self) -> Option<&PhysicalBasetype>
Returns Some
if self is a PhysicalBasetype
, None
otherwise.
sourcefn is_equal(&self, other: &dyn PhysicalType) -> bool
fn is_equal(&self, other: &dyn PhysicalType) -> bool
Check if two physical types are equal.
sourcefn resolution_func(&self) -> Option<usize>
fn resolution_func(&self) -> Option<usize>
The resolution function associated with this type.
sourcefn as_subtype(&self) -> Option<&PhysicalSubtype<'_>>
fn as_subtype(&self) -> Option<&PhysicalSubtype<'_>>
Returns Some
if self is a PhysicalSubtype
, None
otherwise.
sourcefn unwrap_basetype(&self) -> &PhysicalBasetype
fn unwrap_basetype(&self) -> &PhysicalBasetype
Returns an &PhysicalBasetype
or panics if the type is not a basetype.
sourcefn unwrap_subtype(&self) -> &PhysicalSubtype<'_>
fn unwrap_subtype(&self) -> &PhysicalSubtype<'_>
Returns an &PhysicalSubtype
or panics if the type is not a subtype.
sourceimpl Type for PhysicalBasetype
impl Type for PhysicalBasetype
sourcefn is_discrete(&self) -> bool
fn is_discrete(&self) -> bool
Check if this is a discrete type. Read more
sourcefn is_numeric(&self) -> bool
fn is_numeric(&self) -> bool
Check if this is a numeric type. Read more
sourcefn is_composite(&self) -> bool
fn is_composite(&self) -> bool
Check if this is a composite type. Read more
sourcefn into_owned<'a>(self) -> OwnedType<'a> where
Self: 'a,
fn into_owned<'a>(self) -> OwnedType<'a> where
Self: 'a,
Convert into an owned type.
sourcefn is_implicitly_castable(&self, _into: &dyn Type) -> bool
fn is_implicitly_castable(&self, _into: &dyn Type) -> bool
Check if the type can be implicitly cast to another.
impl Eq for PhysicalBasetype
impl StructuralEq for PhysicalBasetype
impl StructuralPartialEq for PhysicalBasetype
Auto Trait Implementations
impl RefUnwindSafe for PhysicalBasetype
impl Send for PhysicalBasetype
impl Sync for PhysicalBasetype
impl Unpin for PhysicalBasetype
impl UnwindSafe for PhysicalBasetype
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