Skip to main content

CustomType

Trait CustomType 

Source
pub trait CustomType {
    const CUSTOM_TYPE: &'static CustomType<'static>;
}
Expand description

Custom type introspection.

This trait is similar to crate::introspect::Type but provides custom type definitions that include the type name and are suitable for IDL generation. While crate::introspect::Type returns inline type information, this trait returns named custom type definitions.

§Examples

use zlink_core::introspect::CustomType;
use zlink_core::idl::{self, Field, CustomObject};

struct Point {
    x: f64,
    y: f64,
}

impl CustomType for Point {
    const CUSTOM_TYPE: &'static idl::CustomType<'static> = &{
        static FIELD_X: Field<'static> = Field::new("x", &zlink_core::idl::Type::Float, &[]);
        static FIELD_Y: Field<'static> = Field::new("y", &zlink_core::idl::Type::Float, &[]);
        static FIELDS: &[&Field<'static>] = &[&FIELD_X, &FIELD_Y];

        idl::CustomType::Object(CustomObject::new("Point", FIELDS, &[]))
    };
}

Required Associated Constants§

Source

const CUSTOM_TYPE: &'static CustomType<'static>

The custom type information including the type name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§