[][src]Attribute Macro sanitizeable_derive::sanitizeable

#[sanitizeable]

Derive the Serializeable trait and create all required structs

Use this to create two different structs, one with all fields and one which only has the fields that are not marked as #[private].

This macro additionally creates a container struct which is used to access the data and a union which you should not use directly. The default names for these types are derived from the name of your struct

A struct called Test will result in the following structs being created:

  • public: TestPublic
  • private: TestPrivate
  • container: Test
  • union: TestUnion

You can change the names of all of these by using the following attributes:

  • #[public_name = "..."]
  • #[private_name = "..."]
  • #[container_name = "..."]
  • #[union_name = "..."]

You can also apply attributes to only one of the variants by using

  • #[public_attr::your_attribute]
  • #[private_attr::your_attribute]

Note that this works both on the whole struct as well as on specific fields You are however not able use the cfg attribute, since that would break internal layout guarantees.

To use the resulting types you need to import the Sanitizeable trait. You can then call the public, public_mut, private, private_mut and into_private methods on the container type.

Contructing the container type can be done by using the from_private method defined on it.

There is not currenty a into_public method, since that is pretty difficult to do due to how Drop works. This functionality might be added in the future.