Views
Walks existing reflected member tables without copying or allocating them.
Module std.reflection
import std.reflection;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
FieldView
pub final class FieldViewWalks existing reflected member tables without copying or allocating them.
Each view stores a descriptor and query. Each cursor snapshots the selected count and advances independently. The descriptors borrow their published generation; retain neither view nor cursor beyond that generation.
Example
module example.reflection_views;
from std.reflection import TypeOf, MemberQuery;
attribute Marker {}
[Marker] pub struct Sample {
[Marker] pub Value: i32;
[Marker] pub Total: i32 { get; set; }
[Marker] pub readonly fn Read([param: Marker] Amount: i32) -> i32 {
return Value + Amount;
}
}
fn Main() -> i32 {
let Type = TypeOf<Sample>();
if !Type.HasAttribute<Marker>() { return 4; }
let Field = switch Type.FindField("Value") {
case .Ok { Value = Found } => break Found;
case .Err { Error = _ } => return 1;
};
let Property = switch Type.FindProperty("Total") {
case .Ok { Value = Found } => break Found;
case .Err { Error = _ } => return 2;
};
if Field.Name != "Value" || Property.Name != "Total" ||
!Field.HasAttribute<Marker>() || !Property.HasAttribute<Marker>() {
return 3;
}
var Count = 0;
for TypeAttribute in Type.Attributes() { Count += 1; }
for TypeEffective in Type.EffectiveAttributes() { Count += 1; }
for TypeSelected in Type.AttributesOf<Marker>() { Count += 1; }
for EffectiveSelected in Type.EffectiveAttributesOf<Marker>() { Count += 1; }
if !Type.HasEffectiveAttribute<Marker>() { return 5; }
if Type.AttributeSite() is .Some { Value = Site } {
if !Site.HasAttribute<Marker>() || !Site.HasEffectiveAttribute<Marker>() { return 6; }
for SiteDirect in Site.Attributes() { Count += 1; }
for SiteEffective in Site.EffectiveAttributes() { Count += 1; }
}
for FieldAttribute in Field.Attributes() { Count += 1; }
for FieldEffective in Field.EffectiveAttributes() { Count += 1; }
for PropertyAttribute in Property.Attributes() { Count += 1; }
for PropertyEffective in Property.EffectiveAttributes() { Count += 1; }
for IteratedField in Type.Fields() { Count += 1; }
for IteratedProperty in Type.Properties(MemberQuery.Declared) { Count += 1; }
for Method in Type.Methods() {
for MethodAttribute in Method.Attributes() { Count += 1; }
for MethodEffective in Method.EffectiveAttributes() { Count += 1; }
if Method.HasAttribute<Marker>() {
if Method.ParameterAt(0) is .Some { Value = Parameter } {
for ParameterAttribute in Parameter.Attributes() { Count += 1; }
for ParameterEffective in Parameter.EffectiveAttributes() { Count += 1; }
if Parameter.HasAttribute<Marker>() { Count += 1; }
}
}
}
return Count;
}FieldView.CreateIterator
pub readonly fn CreateIterator() -> FieldIteratorStarts independent field traversal. Return: Allocation-free cursor.
FieldIterator
pub final class FieldIteratorOwns one field-table cursor.
FieldIterator.Next
pub fn Next() -> FieldInfo?Advances once in canonical field order. Return: Next descriptor or none.
PropertyView
pub final class PropertyViewBorrows one property-table selection.
PropertyView.CreateIterator
pub readonly fn CreateIterator() -> PropertyIteratorStarts independent property traversal. Return: Allocation-free cursor.
PropertyIterator
pub final class PropertyIteratorOwns one property-table cursor.
PropertyIterator.Next
pub fn Next() -> PropertyInfo?Advances once in canonical property order. Return: Next descriptor or none.
MethodView
pub final class MethodViewBorrows one method-table selection.
MethodView.CreateIterator
pub readonly fn CreateIterator() -> MethodIteratorStarts independent method traversal. Return: Allocation-free cursor.
MethodIterator
pub final class MethodIteratorOwns one method-table cursor.
MethodIterator.Next
pub fn Next() -> MethodInfo?Advances once in canonical method order. Return: Next descriptor or none.
TypeAttributeView
pub final class TypeAttributeViewBorrows direct attributes of one type descriptor.
TypeAttributeView.CreateIterator
pub readonly fn CreateIterator() -> TypeAttributeIteratorStarts an independent direct-attribute traversal. Return: Allocation-free cursor.
TypeAttributeIterator
pub final class TypeAttributeIteratorOwns one direct-attribute cursor for a type descriptor.
TypeAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in direct attribute declaration order. Return: Next descriptor or none.
ParameterAttributeView
pub final class ParameterAttributeViewBorrows direct attributes of one parameter descriptor.
ParameterAttributeView.CreateIterator
pub readonly fn CreateIterator() -> ParameterAttributeIteratorStarts an independent direct-attribute traversal. Return: Allocation-free cursor.
ParameterAttributeIterator
pub final class ParameterAttributeIteratorOwns one direct-attribute cursor for a parameter descriptor.
ParameterAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in direct attribute declaration order. Return: Next descriptor or none.
FieldAttributeView
pub final class FieldAttributeViewBorrows direct attributes of one field descriptor.
FieldAttributeView.CreateIterator
pub readonly fn CreateIterator() -> FieldAttributeIteratorStarts an independent direct-attribute traversal. Return: Allocation-free cursor.
FieldAttributeIterator
pub final class FieldAttributeIteratorOwns one direct-attribute cursor for a field descriptor.
FieldAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in direct attribute declaration order. Return: Next descriptor or none.
PropertyAttributeView
pub final class PropertyAttributeViewBorrows direct attributes of one property descriptor.
PropertyAttributeView.CreateIterator
pub readonly fn CreateIterator() -> PropertyAttributeIteratorStarts an independent direct-attribute traversal. Return: Allocation-free cursor.
PropertyAttributeIterator
pub final class PropertyAttributeIteratorOwns one direct-attribute cursor for a property descriptor.
PropertyAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in direct attribute declaration order. Return: Next descriptor or none.
MethodAttributeView
pub final class MethodAttributeViewBorrows direct attributes of one method descriptor.
MethodAttributeView.CreateIterator
pub readonly fn CreateIterator() -> MethodAttributeIteratorStarts an independent direct-attribute traversal. Return: Allocation-free cursor.
MethodAttributeIterator
pub final class MethodAttributeIteratorOwns one direct-attribute cursor for a method descriptor.
MethodAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in direct attribute declaration order. Return: Next descriptor or none.
SiteEffectiveAttributeView
pub final class SiteEffectiveAttributeViewBorrows effective attributes from one site descriptor.
SiteEffectiveAttributeView.CreateIterator
pub readonly fn CreateIterator() -> SiteEffectiveAttributeIteratorStarts an independent effective-attribute traversal. Return: Allocation-free cursor.
SiteEffectiveAttributeIterator
pub final class SiteEffectiveAttributeIteratorOwns one effective-attribute cursor for a site descriptor.
SiteEffectiveAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in effective attribute order. Return: Next descriptor or none.
TypeEffectiveAttributeView
pub final class TypeEffectiveAttributeViewBorrows effective attributes from one type descriptor.
TypeEffectiveAttributeView.CreateIterator
pub readonly fn CreateIterator() -> TypeEffectiveAttributeIteratorStarts an independent effective-attribute traversal. Return: Allocation-free cursor.
TypeEffectiveAttributeIterator
pub final class TypeEffectiveAttributeIteratorOwns one effective-attribute cursor for a type descriptor.
TypeEffectiveAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in effective attribute order. Return: Next descriptor or none.
ParameterEffectiveAttributeView
pub final class ParameterEffectiveAttributeViewBorrows effective attributes from one parameter descriptor.
ParameterEffectiveAttributeView.CreateIterator
pub readonly fn CreateIterator() -> ParameterEffectiveAttributeIteratorStarts an independent effective-attribute traversal. Return: Allocation-free cursor.
ParameterEffectiveAttributeIterator
pub final class ParameterEffectiveAttributeIteratorOwns one effective-attribute cursor for a parameter descriptor.
ParameterEffectiveAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in effective attribute order. Return: Next descriptor or none.
FieldEffectiveAttributeView
pub final class FieldEffectiveAttributeViewBorrows effective attributes from one field descriptor.
FieldEffectiveAttributeView.CreateIterator
pub readonly fn CreateIterator() -> FieldEffectiveAttributeIteratorStarts an independent effective-attribute traversal. Return: Allocation-free cursor.
FieldEffectiveAttributeIterator
pub final class FieldEffectiveAttributeIteratorOwns one effective-attribute cursor for a field descriptor.
FieldEffectiveAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in effective attribute order. Return: Next descriptor or none.
PropertyEffectiveAttributeView
pub final class PropertyEffectiveAttributeViewBorrows effective attributes from one property descriptor.
PropertyEffectiveAttributeView.CreateIterator
pub readonly fn CreateIterator() -> PropertyEffectiveAttributeIteratorStarts an independent effective-attribute traversal. Return: Allocation-free cursor.
PropertyEffectiveAttributeIterator
pub final class PropertyEffectiveAttributeIteratorOwns one effective-attribute cursor for a property descriptor.
PropertyEffectiveAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in effective attribute order. Return: Next descriptor or none.
MethodEffectiveAttributeView
pub final class MethodEffectiveAttributeViewBorrows effective attributes from one method descriptor.
MethodEffectiveAttributeView.CreateIterator
pub readonly fn CreateIterator() -> MethodEffectiveAttributeIteratorStarts an independent effective-attribute traversal. Return: Allocation-free cursor.
MethodEffectiveAttributeIterator
pub final class MethodEffectiveAttributeIteratorOwns one effective-attribute cursor for a method descriptor.
MethodEffectiveAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in effective attribute order. Return: Next descriptor or none.
SiteAttributeView
pub final class SiteAttributeViewBorrows attributes authored at one canonical site.
SiteAttributeView.CreateIterator
pub readonly fn CreateIterator() -> SiteAttributeIteratorStarts independent direct-site traversal. Return: Allocation-free cursor.
SiteAttributeIterator
pub final class SiteAttributeIteratorOwns one direct-site attribute cursor.
SiteAttributeIterator.Next
pub fn Next() -> AttributeInfo?Advances in direct site order. Return: Next descriptor or none.
SiteFilteredAttributeView
pub final class SiteFilteredAttributeView<A>Borrows direct attributes of one exact type from a site descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
SiteFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> SiteFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
SiteFilteredAttributeIterator
pub final class SiteFilteredAttributeIterator<A>Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
SiteFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in direct order. Return: Existing descriptor or none.
SiteEffectiveFilteredAttributeView
pub final class SiteEffectiveFilteredAttributeView<A>Borrows effective attributes of one exact type from a site descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
SiteEffectiveFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> SiteEffectiveFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
SiteEffectiveFilteredAttributeIterator
pub final class SiteEffectiveFilteredAttributeIterator<A>Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
SiteEffectiveFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in effective order. Return: Existing descriptor or none.
TypeFilteredAttributeView
pub final class TypeFilteredAttributeView<A>Borrows direct attributes of one exact type from a type descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
TypeFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> TypeFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
TypeFilteredAttributeIterator
pub final class TypeFilteredAttributeIterator<A>Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
TypeFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in direct order. Return: Existing descriptor or none.
TypeEffectiveFilteredAttributeView
pub final class TypeEffectiveFilteredAttributeView<A>Borrows effective attributes of one exact type from a type descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
TypeEffectiveFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> TypeEffectiveFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
TypeEffectiveFilteredAttributeIterator
pub final class TypeEffectiveFilteredAttributeIterator<A>Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
TypeEffectiveFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in effective order. Return: Existing descriptor or none.
ParameterFilteredAttributeView
pub final class ParameterFilteredAttributeView<A>Borrows direct attributes of one exact type from a parameter descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
ParameterFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> ParameterFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
ParameterFilteredAttributeIterator
pub final class ParameterFilteredAttributeIterator<A>Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
ParameterFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in direct order. Return: Existing descriptor or none.
ParameterEffectiveFilteredAttributeView
pub final class ParameterEffectiveFilteredAttributeView<A>Borrows effective attributes of one exact type from a parameter descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
ParameterEffectiveFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> ParameterEffectiveFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
ParameterEffectiveFilteredAttributeIterator
pub final class ParameterEffectiveFilteredAttributeIterator<A>Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
ParameterEffectiveFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in effective order. Return: Existing descriptor or none.
FieldFilteredAttributeView
pub final class FieldFilteredAttributeView<A>Borrows direct attributes of one exact type from a field descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
FieldFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> FieldFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
FieldFilteredAttributeIterator
pub final class FieldFilteredAttributeIterator<A>Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
FieldFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in direct order. Return: Existing descriptor or none.
FieldEffectiveFilteredAttributeView
pub final class FieldEffectiveFilteredAttributeView<A>Borrows effective attributes of one exact type from a field descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
FieldEffectiveFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> FieldEffectiveFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
FieldEffectiveFilteredAttributeIterator
pub final class FieldEffectiveFilteredAttributeIterator<A>Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
FieldEffectiveFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in effective order. Return: Existing descriptor or none.
PropertyFilteredAttributeView
pub final class PropertyFilteredAttributeView<A>Borrows direct attributes of one exact type from a property descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
PropertyFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> PropertyFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
PropertyFilteredAttributeIterator
pub final class PropertyFilteredAttributeIterator<A>Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
PropertyFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in direct order. Return: Existing descriptor or none.
PropertyEffectiveFilteredAttributeView
pub final class PropertyEffectiveFilteredAttributeView<A>Borrows effective attributes of one exact type from a property descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
PropertyEffectiveFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> PropertyEffectiveFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
PropertyEffectiveFilteredAttributeIterator
pub final class PropertyEffectiveFilteredAttributeIterator<A>Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
PropertyEffectiveFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in effective order. Return: Existing descriptor or none.
MethodFilteredAttributeView
pub final class MethodFilteredAttributeView<A>Borrows direct attributes of one exact type from a method descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
MethodFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> MethodFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
MethodFilteredAttributeIterator
pub final class MethodFilteredAttributeIterator<A>Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
MethodFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in direct order. Return: Existing descriptor or none.
MethodEffectiveFilteredAttributeView
pub final class MethodEffectiveFilteredAttributeView<A>Borrows effective attributes of one exact type from a method descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.
MethodEffectiveFilteredAttributeView.CreateIterator
pub readonly fn CreateIterator() -> MethodEffectiveFilteredAttributeIterator<A>Starts an independent filtered traversal. Return: Allocation-free cursor.
MethodEffectiveFilteredAttributeIterator
pub final class MethodEffectiveFilteredAttributeIterator<A>Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.
MethodEffectiveFilteredAttributeIterator.Next
pub fn Next() -> AttributeInfo?Finds the next matching attribute in effective order. Return: Existing descriptor or none.