Skip to main content

Crate facet_styx

Crate facet_styx 

Source
Expand description

§facet-styx

crates.io documentation MIT/Apache-2.0 licensed

Facet integration for the Styx configuration language. Deserialize Styx documents directly into Rust types using reflection.

§Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

…along with corporate sponsors:

AWS Zed Depot

…without whom this work could not exist.

§License

Licensed under either of:

at your option. Styx format support for facet.

This crate provides Styx deserialization and serialization using the facet reflection system.

§Deserialization Example

use facet::Facet;
use facet_styx::from_str;

#[derive(Facet, Debug, PartialEq)]
struct Config {
    name: String,
    port: u16,
}

let styx = "name myapp\nport 8080";
let config: Config = from_str(styx).unwrap();
assert_eq!(config.name, "myapp");
assert_eq!(config.port, 8080);

§Serialization Example

use facet::Facet;
use facet_styx::to_string;

#[derive(Facet, Debug)]
struct Config {
    name: String,
    port: u16,
}

let config = Config { name: "myapp".into(), port: 8080 };
let styx = to_string(&config).unwrap();
assert!(styx.contains("name myapp"));
assert!(styx.contains("port 8080"));

Macros§

trace
Emit a trace-level log message (no-op version).

Structs§

DefaultSchema
Default value wrapper: @default(value @type). If the field is missing, use the default value. Tuple is (default_value, inner_schema).
DeprecatedSchema
Deprecated wrapper: @deprecated(“reason” @type). Marks a field as deprecated; validation warns but doesn’t fail. Tuple is (reason, inner_schema).
DeserializeError
Error produced by the format deserializer.
Documented
A value with documentation metadata.
EnumSchema
Enum schema: @enum{variant @Type, variant @object{…}}. Maps variant names to their payload schemas.
FlattenSchema
Flatten schema: @flatten(@Type). Inlines fields from another type into the containing object.
FloatConstraints
Constraints for @float type.
GenerateSchema
Builder for generating Styx schemas from Facet types.
IntConstraints
Constraints for @int type.
LspExtensionConfig
Configuration for LSP extensions.
MapSchema
Map schema: @map(@V) or @map(@K @V). Vec contains 1 element (value type, key defaults to @string) or 2 elements (key, value).
Meta
Schema metadata.
ObjectKey
A key in an object schema.
ObjectSchema
Object schema: @object{field @Schema, @string @Schema}. Maps field keys to their type constraints. Keys can be named fields or type patterns (like @string for catch-all). Keys are wrapped in Documented<ObjectKey> to carry field documentation.
OneOfSchema
One-of schema: @one-of(@type value1 value2 …). Constrains values to a finite set. Tuple is (base_type, allowed_values).
OptionalSchema
Optional schema: @optional(@T). Field can be absent or match the inner type.
RawStyx
A raw Styx value that serializes without quotes and deserializes any value as a string.
SchemaFile
A complete schema file.
SeqSchema
Sequence schema: @seq(@Schema). All elements must match the inner schema.
SerializeOptions
Options for Styx serialization.
StringConstraints
Constraints for @string type.
StyxParser
Streaming Styx parser implementing FormatParser.
StyxSerializeError
Error type for Styx serialization.
StyxSerializer
Styx serializer with configurable formatting options.
TupleSchema
Tuple schema: @tuple(@A @B @C …). Each position has a distinct type, unlike @seq which is homogeneous.
UnionSchema
Union schema: @union(@A @B …). Value must match one of the listed types.
ValidationError
A validation error.
ValidationResult
Result of validating a document against a schema.
ValidationWarning
A validation warning (non-fatal).
Validator
Validator for Styx documents.

Enums§

Schema
A type constraint (corresponds to Schema @enum{…} in the meta-schema).
SerializeError
Error produced by the shared serializer.
ValidationErrorKind
Kinds of validation errors.

Constants§

META_SCHEMA_SOURCE
The STYX meta-schema source.

Traits§

RenderError
Trait for rendering errors with ariadne diagnostics.

Functions§

from_str
Deserialize a value from a Styx string into an owned type.
from_str_borrowed
Deserialize a value from a Styx string, allowing zero-copy borrowing.
from_str_expr
Deserialize a single value from a Styx expression string.
peek_to_string
Serialize a Peek instance to a Styx string.
peek_to_string_expr
Serialize a Peek instance to a Styx expression string.
peek_to_string_with_options
Serialize a Peek instance to a Styx string with custom options.
schema_file_from_type
Generate a SchemaFile directly from a Facet type.
schema_from_type
Generate a Styx schema string from a Facet type.
to_string
Serialize a value to a Styx string.
to_string_compact
Serialize a value to a compact Styx string (single line, comma separators).
to_string_with_options
Serialize a value to a Styx string with custom options.
validate
Convenience function to validate a document against a schema.
validate_as
Convenience function to validate a value against a named type.