pub struct ScalarSubtype<'t, T: Type + ?Sized + 't, C: Clone> { /* private fields */ }
Expand description

A subtype of a scalar type.

Scalar types may be subtyped by a range constraint.

Implementations

Create a new enumeration subtype.

Example
use moore_vhdl::ty2::{Type, TypeMark, EnumBasetype, EnumSubtype, Range};
use moore_common::name::get_name_table;

let ty = EnumBasetype::new(vec![
    "first".into(),
    "second".into(),
    '0'.into(),
    '1'.into(),
]);
let tm = TypeMark::new(
    get_name_table().intern("MY_TYPE", false),
    &ty,
);
let subty = EnumSubtype::new(&tm, Range::ascending(1usize, 2usize)).unwrap();

assert_eq!(format!("{}", subty), "MY_TYPE range second to '0'");

Create a new real subtype.

Returns Some(...) if range is a subrange of the real, or None otherwise.

Example
use moore_common::name::get_name_table;
use moore_vhdl::ty2::{Type, TypeMark, FloatingBasetype, FloatingSubtype, Range};

let ty = FloatingBasetype::new(Range::ascending(0.0, 1.0));
let tm = TypeMark::new(
    get_name_table().intern("UNIT", false),
    &ty,
);
let a = FloatingSubtype::new(&tm, Range::ascending(0.0, 0.5)).unwrap();
let b = FloatingSubtype::new(&tm, Range::descending(0.5, 0.0)).unwrap();

assert_eq!(format!("{}", a), "UNIT range 0 to 0.5");
assert_eq!(format!("{}", b), "UNIT range 0.5 downto 0");

Create a new integer subtype.

Returns Some(...) if range is a subrange of the integer, or None otherwise.

Example
use moore_vhdl::ty2::{Type, TypeMark, IntegerBasetype, IntegerSubtype, Range};
use moore_common::name::get_name_table;

let ty = IntegerBasetype::new(Range::ascending(0usize, 255usize));
let tm = TypeMark::new(
    get_name_table().intern("BYTE", false),
    &ty,
);
let a = IntegerSubtype::new(&tm, Range::ascending(0usize, 15usize)).unwrap();
let b = IntegerSubtype::new(&tm, Range::descending(15usize, 0usize)).unwrap();

assert_eq!(format!("{}", a), "BYTE range 0 to 15");
assert_eq!(format!("{}", b), "BYTE range 15 downto 0");

Create a new integer subtype.

Returns Some(...) if range is a subrange of the integer, or None otherwise.

Example
use moore_vhdl::ty2::{Type, TypeMark, PhysicalUnit, PhysicalBasetype, PhysicalSubtype, Range};
use moore_common::name::get_name_table;

let ty = PhysicalBasetype::new(Range::ascending(-1000isize, 1000isize), vec![
    PhysicalUnit::primary(get_name_table().intern("fs", false), 1),
    PhysicalUnit::secondary(get_name_table().intern("ps", false), 1000, 1000, 0),
], 0);
let tm = TypeMark::new(
    get_name_table().intern("TIME", false),
    &ty,
);
let a = PhysicalSubtype::new(&tm, Range::ascending(0isize, 100isize)).unwrap();
let b = PhysicalSubtype::new(&tm, Range::descending(100isize, 0isize)).unwrap();

assert_eq!(format!("{}", a), "TIME range 0 to 100");
assert_eq!(format!("{}", b), "TIME range 100 downto 0");

Trait Implementations

Allocate a value of type T.

Allocate a value of type T.

Allocate a value of type T.

Allocate a value of type T.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

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

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.