drop_with_owned_fields

Attribute Macro drop_with_owned_fields 

Source
#[drop_with_owned_fields]
Expand description

Annotation required on a type in order for DropWithOwnedFields to be implementable for it.

The attribute shall then define a companion struct …ඞFields,

  • either as an “anonymous”/“private” (sealed) type, then only nameable through the convenience DestructuredFieldsOf<Self> type alias and naming abstraction layer;

    This is the case when feeding it an attribute arg of as _.

    The following, for instance, fails to compile:

    use ::drop_with_owned_fields::drop_with_owned_fields;
    
    #[drop_with_owned_fields(as _)]
    struct Foo {
        // …
    }
    
    fn main() {
        let _: FooFields; // Error
    }

    with:

    error[E0412]: cannot find type `FooFields` in this scope
      --> src/_lib.rs:114:12
       |
    10 |     let _: FooFields; // Error
       |            ^^^^^^^^^^ not found in this scope
       |
  • or, when feeding it an attribute arg of as $($pub:vis)? struct $FooFieldsName:ident, as a properly $FooFieldsName-named, and $pub-visible, type.

    use ::drop_with_owned_fields::drop_with_owned_fields;
    
    #[drop_with_owned_fields(as pub(crate) struct FooFields)]
    pub struct Foo {
        // …
    }
    
    fn main() {
        let _: FooFields; // ✅
    }

See the main crate docs for more info.