Skip to main content

Crate koruma_derive_core

Crate koruma_derive_core 

Source
Expand description

§koruma-derive-core

Docs Crates.io

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§

FieldInfo
Field information extracted from parsing #[koruma(...)] attributes.
KorumaAttr
Represents a parsed #[koruma(...)] attribute which can contain multiple validators separated by commas: #[koruma(Validator1(a = 1), Validator2(b = 2))]
ShowcaseAttr
Parsed showcase attribute: #[showcase(name = "...", description = "...", create = |input| { ... })]
StructOptions
Struct-level options parsed from #[koruma(...)]
ValidationInfo
Validation information extracted from #[koruma(...)] attributes.
ValidatorAttr
Represents a single parsed validator: ValidatorName(arg = value, ...) or ValidatorName::<_>(arg = value, ...) or ValidatorName::<SomeType>(arg = value, ...) Also supports fully-qualified paths like module::path::ValidatorName::<_>.

Enums§

ParseFieldResult
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>.