Struct LinkTable

Source
pub struct LinkTable<K> { /* private fields */ }
Expand description

Table for tracking links between ports.

Two ports are connected when they share the same link. Links are named and scoped via closed regions. Links from one closed region are not visible in another. Open regions are considered to form the same scope as their parent region. Links do not have a unique point of declaration.

The link table keeps track of an association between a key of type K and the link indices within each closed region. When resolving links from a text format, K is the name of the link as a string slice. However the link table might is also useful in other contexts where the key is not a string when constructing a module from a different representation.

§Examples

let mut links = LinkTable::new();
links.enter(RegionId(0));
let foo_0 = links.use_link("foo");
let bar_0 = links.use_link("bar");
assert_eq!(foo_0, links.use_link("foo"));
assert_eq!(bar_0, links.use_link("bar"));
let (num_links, num_ports) = links.exit();
assert_eq!(num_links, 2);
assert_eq!(num_ports, 4);

Implementations§

Source§

impl<K> LinkTable<K>
where K: Copy + Eq + Hash,

Source

pub fn new() -> Self

Create a new empty link table.

Source

pub fn enter(&mut self, region: RegionId)

Enter a new scope for the given closed region.

Source

pub fn exit(&mut self) -> (u32, u32)

Exit a previously entered scope, returning the number of links and ports in the scope.

Resolve a link key to a link index, adding one more port to the current scope.

If the key has not been used in the current scope before, it will be added to the link table.

§Panics

Panics if there are no open scopes.

Source

pub fn clear(&mut self)

Reset the link table to an empty state while preserving allocated memory.

Trait Implementations§

Source§

impl<K: Clone> Clone for LinkTable<K>

Source§

fn clone(&self) -> LinkTable<K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug> Debug for LinkTable<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K> Default for LinkTable<K>
where K: Copy + Eq + Hash,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K> Freeze for LinkTable<K>

§

impl<K> RefUnwindSafe for LinkTable<K>
where K: RefUnwindSafe,

§

impl<K> Send for LinkTable<K>
where K: Send,

§

impl<K> Sync for LinkTable<K>
where K: Sync,

§

impl<K> Unpin for LinkTable<K>
where K: Unpin,

§

impl<K> UnwindSafe for LinkTable<K>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<'a, S, T> View<'a, &S> for T
where T: View<'a, S>, S: Copy,

Source§

fn view(module: &'a Module<'a>, id: &S) -> Option<T>

Attempt to interpret a subpart of a module as this type.