Struct CompositionGraph

Source
pub struct CompositionGraph<'a> { /* private fields */ }
Expand description

Represents a composition graph used to compose a new component from other components.

Implementations§

Source§

impl<'a> CompositionGraph<'a>

Source

pub fn new() -> Self

Constructs a new composition graph.

Source

pub fn add_component(&mut self, component: Component<'a>) -> Result<ComponentId>

Adds a new component to the graph.

The component name must be unique.

Source

pub fn get_component( &self, id: impl Into<ComponentId>, ) -> Option<&Component<'a>>

Gets a component from the graph.

Source

pub fn get_component_by_name( &self, name: &str, ) -> Option<(ComponentId, &Component<'a>)>

Gets a component from the graph by name.

Source

pub fn remove_component(&mut self, id: impl Into<ComponentId>)

Removes a component from the graph.

All instances and connections relating to the component will also be removed.

Source

pub fn instantiate(&mut self, id: impl Into<ComponentId>) -> Result<InstanceId>

Creates a new instance of a component in the composition graph.

Source

pub fn get_component_of_instance( &self, id: impl Into<InstanceId>, ) -> Option<(ComponentId, &Component<'_>)>

Gets the component of the given instance.

Source

pub fn remove_instance(&mut self, id: impl Into<InstanceId>)

Removes an instance from the graph.

All connections relating to the instance will also be removed.

Source

pub fn connect( &mut self, source: impl Into<InstanceId> + Copy, source_export: Option<impl Into<ExportIndex> + Copy>, target: impl Into<InstanceId> + Copy, target_import: impl Into<ImportIndex> + Copy, ) -> Result<()>

Creates a connection (edge) between instances in the composition graph.

A connection represents an instantiation argument.

If source_export is None, the source instance itself is used as the instantiation argument.

Source

pub fn disconnect( &mut self, source: impl Into<InstanceId>, target: impl Into<InstanceId>, target_import: impl Into<ImportIndex>, ) -> Result<()>

Disconnects a previous connection between instances.

Requires that the source and target instances are valid.

If the source and target are not connected via the target’s import, then this is a no-op.

Source

pub fn validate_connection( &self, source: impl Into<InstanceId>, source_export: Option<impl Into<ExportIndex>>, target: impl Into<InstanceId>, target_import: impl Into<ImportIndex>, ) -> Result<()>

Validates a connection between two instances in the graph.

Use None for source_export to signify that the instance itself should be the source for the connection.

Returns Err(_) if the connection would not be valid.

Source

pub fn encode(&self, options: EncodeOptions) -> Result<Vec<u8>>

Encodes the current composition graph as a WebAssembly component.

Trait Implementations§

Source§

impl<'a> Debug for CompositionGraph<'a>

Source§

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

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

impl<'a> Default for CompositionGraph<'a>

Source§

fn default() -> CompositionGraph<'a>

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

Auto Trait Implementations§

§

impl<'a> !Freeze for CompositionGraph<'a>

§

impl<'a> !RefUnwindSafe for CompositionGraph<'a>

§

impl<'a> !Send for CompositionGraph<'a>

§

impl<'a> !Sync for CompositionGraph<'a>

§

impl<'a> Unpin for CompositionGraph<'a>

§

impl<'a> UnwindSafe for CompositionGraph<'a>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.