sycamore::reactive

Macro impl_into_maybe_dyn

macro_rules! impl_into_maybe_dyn {
    ($ty:ty $(; $($from:ty),*)?) => { ... };
}
Expand description

A macro that makes it easy to write implementations for Into<MaybeDyn<T>>.

Because of Rust orphan rules, you can only implement Into<MaybeDyn<T>> for types that are defined in the current crate. To work around this limitation, the newtype pattern can be used.

ยงExample


struct MyType;

struct OtherType;

impl From<OtherType> for MyType {
    fn from(_: OtherType) -> Self {
        todo!();
    }
}

// You can also list additional types that can be converted to `MaybeDyn<MyType>`.
impl_into_maybe_dyn!(MyType; OtherType);