Expand description
§koruma-derive-core
Parsing utilities for koruma derive macros. This crate exposes the data model for
#[koruma(...)] attributes and is intended for tooling or proc-macro internals.
Most users should depend on koruma (or koruma-derive) instead of this crate directly.
Core parsing types and utilities for koruma derive macros.
This crate provides a public API for parsing #[koruma(...)] attributes,
allowing consumers to analyze koruma validation metadata without depending
on the proc-macro crate directly.
§Example
ⓘ
use koruma_derive_core::{parse_field, ParseFieldResult, FieldInfo};
use syn::Field;
fn analyze_field(field: &Field) {
match parse_field(field, 0) {
ParseFieldResult::Valid(info) => {
println!("Field {} has {} validators", info.name, info.field_validators.len());
for v in &info.field_validators {
println!(" - {}", v.name());
}
}
ParseFieldResult::Skip => println!("Field skipped"),
ParseFieldResult::Error(e) => println!("Parse error: {}", e),
}
}Structs§
- Field
Info - Field information extracted from parsing
#[koruma(...)]attributes. - Koruma
Attr - Represents a parsed
#[koruma(...)]attribute which can contain multiple validators separated by commas:#[koruma(Validator1(a = 1), Validator2(b = 2))] - Showcase
Attr - Parsed showcase attribute:
#[showcase(name = "...", description = "...", create = |input| { ... })] - Struct
Options - Struct-level options parsed from
#[koruma(...)] - Validation
Info - Validation information extracted from
#[koruma(...)]attributes. - Validator
Attr - Represents a single parsed validator:
ValidatorName(arg = value, ...)orValidatorName::<_>(arg = value, ...)orValidatorName::<SomeType>(arg = value, ...)Also supports fully-qualified paths likemodule::path::ValidatorName::<_>.
Enums§
- Parse
Field Result - Result of parsing a field with
#[koruma(...)]attribute.
Functions§
- contains_
infer_ type - Check if a type contains any infer placeholders (
_). - expr_
as_ simple_ ident - Check if an expression is a simple identifier (bare field name like
password). - find_
showcase_ attr - Find and parse showcase attribute from struct
- find_
value_ field - Find the field marked with
#[koruma(value)]and return its name and type. - first_
generic_ arg - Extract the first generic type argument from a type.
- is_
option_ infer_ type - Check if a type is
Option<_>(Option wrapping an infer placeholder). - is_
option_ type - Check if a field type is
Option<T>. - option_
inner_ type - Extract the inner type T from
Option<T>. - parse_
field - Parse a single field and extract its koruma validation information.
- parse_
struct_ options - Parse struct-level
#[koruma(...)]attributes from a list of attributes. - substitute_
infer_ type - Substitute infer placeholders (
_) in a type with the actual inferred type. - type_
to_ ident - Extract the ident (name) from a type path.
- vec_
inner_ type - Extract the inner type T from
Vec<T>.