#[derive(Omit)]
{
// Attributes available to this derive:
#[omit]
}
Expand description
Constructs structs by omitting the set of fields from the original struct.
§Example
#[derive(Omit)]
#[omit(
arg(ident = OmitAuthorContent, fields(author, content), derive(Debug)),
arg(ident = OmitLikedComments, fields(liked, comments))
)]
pub struct Article {
author: String,
content: String,
liked: usize,
comments: String,
}The above code will generate the following structs:
#[derive(Debug)]
pub struct OmitAuthorContent {
liked: usize,
comments: String,
}
pub struct OmitLikedComments {
author: String,
content: String,
}Several trait implementations are also generated:
From<Article>forOmitAuthorContentFrom<Article>forOmitLikedComments
§Attributes
ⓘ
#[derive(Omit)]
#[omit(
[forward_attrs(<ATTR, ...> | not(<ATTR, ...>))], // Forward specific attributes to all generated structs
arg(
ident = <IDENT>, // The identifier of the generated struct
fields(<FIELD>, ...), // The fields to omit from the original struct
[derive(<DERIVE>, ...)], // Derive attributes for the generated struct
[forward_attrs(<ATTR, ...> | not(<ATTR, ...>))], // Forward specific attributes to the generated struct
// If given, will override the container level `forward_attrs`
), ...
)]
pub struct BasedStruct {
#[omit(
#[forward_attrs(<ATTR, ...> | not(<ATTR, ...>))], // Forward specific attributes to the generated field
// If given, will override the container level and arg level `forward_attrs`
)]
field: FieldType,
}