component-shape-gpui 0.3.4

GPUI component shape runtime contracts and macros.
Documentation
use std::marker::PhantomData;
use std::str::FromStr;

use component_shape_gpui::{
    ComponentShapeMetadata as _, GpuiComponentRender, GpuiComponentShape, RenderCapability,
    ValueBindingCapability, component_shape,
};

pub struct InputState<T>(PhantomData<T>);

impl<T> InputState<T> {
    fn new(_window: &mut gpui_kit::Window, _cx: &mut gpui_kit::Context<'_, Self>) -> Self {
        Self(PhantomData)
    }
}

pub struct GenericInput<T>(PhantomData<T>);

impl<T> GenericInput<InputState<T>> {
    pub fn new(_entity: &gpui_kit::Entity<InputState<T>>) -> impl gpui_kit::IntoElement {
        gpui_kit::div()
    }
}

component_shape! {
    pub struct InputShape<T = String>
    where
        T: FromStr + ToString + 'static,
    {
        type State = InputState<T>;
        component = GenericInput<_>;
        value = T;
    }
}

fn main() {
    assert!(<InputShape as GpuiComponentShape>::RenderComponent::RENDERS);
    assert_eq!(
        InputShape::<String>::CAPABILITIES.render(),
        RenderCapability::Component
    );
    assert_eq!(
        InputShape::<String>::CAPABILITIES.value_binding(),
        ValueBindingCapability::None
    );
}