Skip to main content

DataTypeTrait

Trait DataTypeTrait 

Source
pub trait DataTypeTrait<UserState>: PartialEq + Eq {
    // Required methods
    fn data_type_color(&self, user_state: &mut UserState) -> Color32;
    fn name(&self) -> Cow<'_, str>;
}
Expand description

This trait must be implemented by the DataType generic parameter of the Graph. This trait tells the library how to visually expose data types to the user.

Required Methods§

Source

fn data_type_color(&self, user_state: &mut UserState) -> Color32

The associated port color of this datatype

Source

fn name(&self) -> Cow<'_, str>

The name of this datatype. Return type is specified as Cow because some implementations will need to allocate a new string to provide an answer while others won’t.

§Example (borrowed value)

Use this when you can get the name of the datatype from its fields or as a &’static str. Prefer this method when possible.

pub struct DataType { name: String }

impl DataTypeTrait<()> for DataType {
    fn name(&self) -> std::borrow::Cow<str> {
        Cow::Borrowed(&self.name)
    }
}
§Example (owned value)

Use this when you can’t derive the name of the datatype from its fields.

pub struct DataType { some_tag: i32 }

impl DataTypeTrait<()> for DataType {
    fn name(&self) -> std::borrow::Cow<str> {
        Cow::Owned(format!("Super amazing type #{}", self.some_tag))
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§