Macro freya::prelude::default_impl

macro_rules! default_impl {
    (
        $ty:ident
        // Accept generics
        < T $(, $gen:ident $(: $gen_bound:path)?)* $(,)?>
        // Accept extra bounds
        $(
            where
                $(
                    $extra_bound_ty:ident: $extra_bound:path
                ),+
        )?
    ) => { ... };
}
Expand description

This macro is used to generate a impl Default block for any type with the function new_maybe_sync that takes a generic T

§Example

use generational_box::*;
use dioxus::prelude::*;

struct MyCopyValue<T: 'static, S: Storage<T>> {
    value: CopyValue<T, S>,
}

impl<T: 'static, S: Storage<T>> MyCopyValue<T, S> {
    fn new_maybe_sync(value: T) -> Self {
        Self { value: CopyValue::new_maybe_sync(value) }
    }
}

impl<T: 'static, S: Storage<T>> Readable for MyCopyValue<T, S> {
    type Target = T;
    type Storage = S;

    fn try_read_unchecked(
        &self,
    ) -> Result<ReadableRef<'static, Self>, generational_box::BorrowError> {
        self.value.try_read_unchecked()
    }

    fn peek_unchecked(&self) -> ReadableRef<'static, Self> {
        self.value.read_unchecked()
    }
}

default_impl!(MyCopyValue<T, S: Storage<T>>);