Derive Macro bagel::Stor

source · []
#[derive(Stor)]
{
    // Attributes available to this derive:
    #[stor_skip]
    #[phantom]
}
Expand description

Stor: Get the setters derived

Stor takes the fields in order and generates setters for each field. For example, if you have fields named userid and name, then the setters generated will be set_userid and set_name, accepting values for the appropriate types. In other words, set_* named methods will be derived per your fields.

Example

use bagel::Stor;
#[derive(Stor)]
struct MyStruct {
    name: String,
    userid: u64,
}

let mut ms = MyStruct { name: "Sayan".to_owned(), userid: 1 };
assert_eq!(ms.name, "Sayan");
assert_eq!(ms.userid, 1);
ms.set_userid(0);
assert_eq!(ms.userid, 0);

Attributes

The following attributes are available:

  • #[phantom]: Skips the stor for the specified field(s), assuming they are PhantomData fields. This has the same effect as #[stor_skip] but it makes it easier to use with the other macros, avoiding the need to write skips for phantom fields specifically
  • #[stor_skip]: Skips the stor for the specified field(s)

Doc-comments

The Stor macro will automatically add a doc comment of the form:

Sets the value for the `<struct_field>` field in struct [`<struct_name>`]