Interop

Stof was created for interoperability and extensibility.

Reads and writes JSON, YAML, TOML, and more. Drop it into your existing stack.


Example: YAML in, JSON out

Start with a server config you already have:

# server.yaml
server:
  port: 4000
  address: "my-server.com"
  memory: 3000
  ttl: 5000

Create our server Stof type with validation meta-logic:

// types.stof

#[type]
Server: {
    #[schema((target_val: int): bool => target_val > 1024 && target_val <= 65536)]
    int port: 8080

    #[schema((target_val: str): bool => target_val != "")]
    str! address: "localhost"

    /// 3000 from YAML becomes 3000MB β€” auto-converted to GiB for display
    #[schema((target_val: MiB): bool => target_val >= 512MB)]
    MiB memory: 1GiB

    /// 5000 from YAML becomes 5000ms β€” compared against 1s automatically  
    #[schema((target_val: ms): bool => target_val >= 1s)]
    ms ttl: 30s

    fn url() -> str {
        `https://${self.address}:${self.port}`
    }
}

Parse it into Stof, validate it, and export as JSON:

Run it:

The YAML had no idea what 512MB or 1s meant. Stof did β€” and validated against them automatically.


Supported formats

Format
Read/Parse
Write/Export

JSON

βœ“

βœ“

YAML

βœ“

βœ“

TOML

βœ“

βœ“

Markdown

βœ“

βœ“

URL-Encoded

βœ“

βœ“

Bytes

βœ“

βœ“

BSTF

βœ“

βœ“

Stof

βœ“

βœ“

DOCX

βœ“ (not in TS)

no

Image (png, jpeg, gif, webp, tiff, bmp, ico)

βœ“ (not in TS)

no

PDF

βœ“ (not in TS)

no

pkg (stof packages)

βœ“

βœ“

TXT

βœ“

βœ“

circle-info

Stof formats are extensible β€” adding or changing one is a simple trait implementation in Rust.


What's next?

  • Formats β€” full format reference

  • Schemas β€” validation in depth

  • Types β€” prototypes and casting

Last updated