On Thu Dec 25, 2025 at 9:37 AM CET, Jesung Yang via B4 Relay wrote:
> +/// ## Compile-time Overflow Assertion
> +///
> +/// The following examples do not compile:
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::Into;
> +/// #[derive(Into)]
> +/// #[into(u8)]
> +/// enum Foo {
> +///     // `256` is larger than `u8::MAX`.
> +///     A = 256,
> +/// }
> +/// ```
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::Into;
> +/// #[derive(Into)]
> +/// #[into(u8)]
> +/// enum Foo {
> +///     // `-1` cannot be represented with `u8`.
> +///     A = -1,
> +/// }
> +/// ```

These two are copy-pasted from the `into` macro.

Cheers,
Benno

> +///
> +/// ## Unsupported Cases
> +///
> +/// The following examples do not compile:
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::TryFrom;
> +/// // Tuple-like enums or struct-like enums are not allowed.
> +/// #[derive(TryFrom)]
> +/// enum Foo {
> +///     A(u8),
> +///     B { inner: u8 },
> +/// }
> +/// ```
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::TryFrom;
> +/// // Structs are not allowed.
> +/// #[derive(TryFrom)]
> +/// struct Foo(u8);
> +/// ```
> +#[proc_macro_derive(TryFrom, attributes(try_from))]
> +pub fn derive_try_from(input: TokenStream) -> TokenStream {
> +    let input = parse_macro_input!(input as DeriveInput);
> +    convert::derive_try_from(input)
> +        .unwrap_or_else(syn::Error::into_compile_error)
> +        .into()
> +}

Reply via email to