Expand description
§facet-styx
Facet integration for the Styx configuration language. Deserialize Styx documents directly into Rust types using reflection.
§Sponsors
Thanks to all individual sponsors:
…along with corporate sponsors:
…without whom this work could not exist.
§License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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§
- Default
Schema - Default value wrapper: @default(value @type). If the field is missing, use the default value. Tuple is (default_value, inner_schema).
- Deprecated
Schema - Deprecated wrapper: @deprecated(“reason” @type). Marks a field as deprecated; validation warns but doesn’t fail. Tuple is (reason, inner_schema).
- Documented
- A value with documentation metadata.
- Enum
Schema - Enum schema: @enum{variant @Type, variant @object{…}}. Maps variant names to their payload schemas.
- Flatten
Schema - Flatten schema: @flatten(@Type). Inlines fields from another type into the containing object.
- Float
Constraints - Constraints for @float type.
- Generate
Schema - Builder for generating Styx schemas from Facet types.
- IntConstraints
- Constraints for @int type.
- LspExtension
Config - 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.
- Object
Key - A key in an object schema.
- Object
Schema - Object schema: @object{field @Schema, @string @Schema}.
Maps field keys to their type constraints.
Keys can be named fields or type patterns (like
@stringfor catch-all). Keys are wrapped inDocumented<ObjectKey>to carry field documentation. - OneOf
Schema - One-of schema: @one-of(@type value1 value2 …). Constrains values to a finite set. Tuple is (base_type, allowed_values).
- Optional
Schema - 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.
- Schema
File - A complete schema file.
- SeqSchema
- Sequence schema: @seq(@Schema). All elements must match the inner schema.
- Serialize
Options - Options for Styx serialization.
- String
Constraints - Constraints for @string type.
- Styx
Error - Error that can occur during Styx parsing.
- Styx
Parser - Streaming Styx parser implementing FormatParser.
- Styx
Serialize Error - Error type for Styx serialization.
- Styx
Serializer - Styx serializer with configurable formatting options.
- Tuple
Schema - Tuple schema: @tuple(@A @B @C …). Each position has a distinct type, unlike @seq which is homogeneous.
- Union
Schema - Union schema: @union(@A @B …). Value must match one of the listed types.
- Validation
Error - A validation error.
- Validation
Result - Result of validating a document against a schema.
- Validation
Warning - A validation warning (non-fatal).
- Validator
- Validator for Styx documents.
Enums§
- Deserialize
Error - Error produced by the format deserializer.
- Schema
- A type constraint (corresponds to Schema @enum{…} in the meta-schema).
- Serialize
Error - Error produced by the shared serializer.
- Styx
Error Kind - Kind of Styx error.
- Validation
Error Kind - Kinds of validation errors.
Constants§
- META_
SCHEMA_ SOURCE - The STYX meta-schema source.
Traits§
- Render
Error - 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
Peekinstance to a Styx string. - peek_
to_ string_ expr - Serialize a
Peekinstance to a Styx expression string. - peek_
to_ string_ with_ options - Serialize a
Peekinstance 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.