Skip to main content

Port

Struct Port 

Source
pub struct Port<I: ?Sized + 'static> { /* private fields */ }
Expand description

A port: a component’s request for an interface it does not own.

One generic struct serves all three kinds, since the only difference is which interface it holds — PutPort, GetPort and PeekPort are aliases, not separate types.

The binding lives behind Rc<RefCell<..>> because connection happens through erasure: connect reaches the port as an Rc<dyn Any> and must write to it, so the mutability has to be interior. The component’s own field and the handle connect obtains are two Rcs to the same cell.

Implementations§

Source§

impl<I: ?Sized + 'static> Port<I>

Source

pub fn new() -> Port<I>

A fresh, unconnected port. Default does the same; components get theirs from #[derive(Default)].

Source

pub fn is_bound(&self) -> bool

Has this port been connected?

Source§

impl<T: 'static> Port<dyn PutIf<T>>

Source

pub async fn put(&self, item: T)

Block until the far end has room, then hand the item over.

Source

pub fn try_put(&self, item: T) -> Result<(), T>

Hand the item over only if it fits right now.

Source

pub fn can_put(&self) -> bool

Source§

impl<T: 'static> Port<dyn GetIf<T>>

Source

pub async fn get(&self) -> T

Block until there is an item, then take it out.

Source

pub fn try_get(&self) -> Option<T>

Source

pub fn can_get(&self) -> bool

Source§

impl<T: 'static> Port<dyn PeekIf<T>>

Source

pub async fn peek(&self) -> T

Block until there is an item, then copy it, leaving it in place.

Source

pub fn try_peek(&self) -> Option<T>

Source

pub fn can_peek(&self) -> bool

Source§

impl<T: 'static> Port<dyn PublishIf<T>>

Source

pub fn write(&self, item: &T)

Broadcast an item. Returns immediately, however many subscribers are listening — including none, which is why this does not panic on an unconnected port the way put does. A source that nobody watches is a legitimate testbench (D85).

Source

pub fn has_subscribers(&self) -> bool

Is anyone listening?

Source§

impl<T: 'static> Port<dyn SinkHandle<T>>

Source

pub fn subscribe<S: Subscriber<T>>(&self, subscriber: RustdvShared<S>)

Supply the receiver: hand the port a handle to the subscriber whose write should run for every item.

Called in the subscriber’s build, before any connect phase runs, so it is already in place when the hub comes looking for it. connect chooses the stream; subscribe supplies the receiver.

Source

pub fn subscriber(&self) -> Option<Rc<dyn SinkHandle<T>>>

The subscriber this port was given, if subscribe was called.

Source§

impl<REQ: 'static, RSP: 'static> Port<dyn SeqItemIf<REQ, RSP>>

Source

pub async fn get_next_item(&self) -> SeqItem<REQ>

Block until a sequence has an item ready for this driver.

Source

pub fn try_next_item(&self) -> Option<SeqItem<REQ>>

Take an item only if one is waiting (the UVM’s try_next_item). A driver that must also do something else this clock edge cannot afford the blocking form.

Source

pub fn item_done(&self, rsp: Option<RSP>)

Release the sequence, optionally with its answer.

Source

pub fn put_response(&self, id: TxnId, rsp: RSP)

Answer a request that was released earlier — the pipelined case.

Source

pub fn bind_iface(&self, iface: Rc<dyn SeqItemIf<REQ, RSP>>)

Bind this port directly, for a component that is handed its export at construction rather than wired in a connect phase.

Trait Implementations§

Source§

impl<I: ?Sized + 'static> Clone for Port<I>

Source§

fn clone(&self) -> Self

Another handle to the same binding, not a second port.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<I: ?Sized + 'static> Default for Port<I>

Source§

fn default() -> Self

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

impl<I: ?Sized + 'static> PortField for Port<I>

Source§

type Iface = I

The interface this port demands: dyn PutIf<T>, dyn GetIf<T>, …
Source§

fn slot_any(&self) -> Rc<dyn Any>

The binding cell, erased, so connect can reach it through dyn.
Source§

fn bound(&self) -> bool

Has it been connected?

Auto Trait Implementations§

§

impl<I> !RefUnwindSafe for Port<I>

§

impl<I> !Send for Port<I>

§

impl<I> !Sync for Port<I>

§

impl<I> !UnwindSafe for Port<I>

§

impl<I> Freeze for Port<I>
where I: ?Sized,

§

impl<I> Unpin for Port<I>
where I: ?Sized,

§

impl<I> UnsafeUnpin for Port<I>
where I: ?Sized,

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> 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.