@@ -237,8 +237,8 @@ pub fn iter_variants_derive(input: TokenStream) -> TokenStream {
237
237
unwrap_errors ( iter:: derive ( & ast) ) . into ( )
238
238
}
239
239
240
- /// Derives [`TryFrom<Repr>`] for an enum, where `Repr` is a [primitive representation] specified
241
- /// in `#[repr(...)]`.
240
+ /// Derives [`TryFrom<Repr>`] for a C-like enum, where `Repr` is a [primitive representation]
241
+ /// specified in `#[repr(...)]`.
242
242
///
243
243
/// [`TryFrom<Repr>`]: https://doc.rust-lang.org/std/convert/trait.TryFrom.html
244
244
/// [primitive representation]: https://doc.rust-lang.org/reference/type-layout.html#primitive-representations
@@ -263,13 +263,25 @@ pub fn iter_variants_derive(input: TokenStream) -> TokenStream {
263
263
/// assert_eq!(Err(()), Direction::try_from(0u8));
264
264
/// assert_eq!(Err(()), Direction::try_from(5u8));
265
265
/// ```
266
+ ///
267
+ /// This macro only works on C-like enums.
268
+ ///
269
+ /// ```compile_fail
270
+ /// #[derive(Debug, Clone, enum_utils::TryFromRepr)]
271
+ /// #[repr(u8)]
272
+ /// pub enum Letter {
273
+ /// A,
274
+ /// B,
275
+ /// Other(u8),
276
+ /// }
277
+ /// ```
266
278
#[ proc_macro_derive( TryFromRepr , attributes( enumeration) ) ]
267
279
pub fn try_from_repr_derive ( input : TokenStream ) -> TokenStream {
268
280
let ast = parse_macro_input ! ( input as DeriveInput ) ;
269
281
unwrap_errors ( conv:: derive_try_from_repr ( & ast) ) . into ( )
270
282
}
271
283
272
- /// Derives [`From<Enum >`] for the [primitive representation] specified in `#[repr(...)]`.
284
+ /// Derives [`From<CLikeEnum >`] for the [primitive representation] specified in `#[repr(...)]`.
273
285
///
274
286
/// [`From<Enum>`]: https://doc.rust-lang.org/std/convert/trait.From.html
275
287
/// [primitive representation]: https://doc.rust-lang.org/reference/type-layout.html#primitive-representations
@@ -290,6 +302,18 @@ pub fn try_from_repr_derive(input: TokenStream) -> TokenStream {
290
302
/// assert_eq!(1u8, North.into());
291
303
/// assert_eq!(4u8, West.into());
292
304
/// ```
305
+ ///
306
+ /// This macro only works on C-like enums.
307
+ ///
308
+ /// ```compile_fail
309
+ /// #[derive(Debug, Clone, enum_utils::TryFromRepr)]
310
+ /// #[repr(u8)]
311
+ /// pub enum Letter {
312
+ /// A,
313
+ /// B,
314
+ /// Other(u8),
315
+ /// }
316
+ /// ```
293
317
#[ proc_macro_derive( ReprFrom , attributes( enumeration) ) ]
294
318
pub fn repr_from_derive ( input : TokenStream ) -> TokenStream {
295
319
let ast = parse_macro_input ! ( input as DeriveInput ) ;
0 commit comments