AttributeTarget
Identifies one semantic declaration target accepted by typed metadata.
Module std.meta
import std.meta;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
AttributeTarget
pub enum AttributeTargetIdentifies one semantic declaration target accepted by typed metadata.
Targets describe declarations and their structural subdeclarations rather than syntax positions. .Any is exclusive when used by AttributeUsage.
Example
module example.attribute_policy;
from std.meta import AttributeRetention, AttributeTarget, AttributeUsage;
[AttributeUsage(.Field, Repeatable = true, Retention = .Runtime)]
[AttributeUsage(.Global, Repeatable = true, Retention = .Runtime)]
pub attribute Label {
pub Text: str;
init(Text: str) { this.Text = Text; }
}
[AttributeUsage(.Type, Retention = .CompileTimeOnly)]
pub attribute BuildHint { init() { } }
[BuildHint]
pub struct Record {
[Label("identifier"), Label("database key")]
pub Id: u64;
}
[Label("current record count")]
pub var RecordCount: i32 = 0;
fn Main() -> i32 { RecordCount += 1; return RecordCount; }AttributeTarget.Any
Any;Selects every legal semantic target and cannot be combined with another target.
AttributeTarget.Module
Module;Selects a source module declaration.
AttributeTarget.Type
Type;Selects a nominal or synonym type declaration.
AttributeTarget.Concept
Concept;Selects a structural concept declaration.
AttributeTarget.Constant
Constant;Selects a typed constant declaration.
AttributeTarget.Field
Field;Selects a stored field declaration.
AttributeTarget.Property
Property;Selects an instance property declaration.
AttributeTarget.Function
Function;Selects an ordinary or external function declaration.
AttributeTarget.Initializer
Initializer;Selects an initializer declaration.
AttributeTarget.Deinitializer
Deinitializer;Selects a deinitializer declaration.
AttributeTarget.Operator
Operator;Selects an operator declaration.
AttributeTarget.Getter
Getter;Selects a property getter subdeclaration.
AttributeTarget.Setter
Setter;Selects a property setter subdeclaration.
AttributeTarget.Parameter
Parameter;Selects one named callable parameter.
AttributeTarget.Return
Return;Selects one callable return subdeclaration.
AttributeTarget.GenericParameter
GenericParameter;Selects one named generic parameter.
AttributeTarget.EnumCase
EnumCase;Selects one enum case declaration.
AttributeTarget.Global
Global;Selects a module runtime storage declaration.