Stof Docs
Star on GitHubStof WebsiteDiscordContact Us
  • 🚀Welcome
  • â„šī¸Resources & Information
  • Book
    • Data Interface
    • Introduction & Design
    • Host Environments
      • Rust
      • TypeScript
        • Extend Stof
        • Import Statement
    • Data Interchange
      • JSON to Stof
      • Importing and Parsing Data
      • Exporting Data
      • REST and Restructure
    • Configuration Files
    • Schemas
      • Renaming Fields
      • Removing Fields
      • Validation & Transformation
        • Example Access
      • Nested Schemas
    • Orchestration
  • Common Concepts
    • Objects
    • Primitive Types
    • Functions
    • Fields
    • Object Types
    • Imports
    • Error Handling
    • Units
    • Casting/Conversions
  • Reference
    • CLI
      • 🏃Run
      • đŸ§ĒTest
      • 📚CLI Libraries
        • Filesystem Library
        • Time Library
        • HTTP Library
    • Stof Language
    • Libraries
      • Standard Library
      • Array/Vector Library
      • Number Library
      • String Library
      • Object Library
      • Function Library
      • Set Library
      • Map Library
      • Data Library
      • Tuple Library
      • Blob Library
      • Boolean Library
    • đŸĒ§Formats
Powered by GitBook
On this page

Was this helpful?

  1. Book
  2. Host Environments

Rust

Embedding Stof in Rust.

PreviousHost EnvironmentsNextTypeScript

Last updated 3 months ago

Was this helpful?

Because Stof is written in Rust, there is a lot of support for using Stof with Rust.

Take a look at our to see how Stof is implemented.

To add Stof to your Rust project, use cargo:

cargo add stof

The main interfaces to Stof are the document (SDoc) and graph (SGraph). If you're working primarily with the Stof language interface (like in the rest of these documents), you won't need to interact with the graph. However, if you need deeper control, the graph organizes and stores the data.

Make sure to check out the of Stof. This will help you get started with deep programmatic control over your Stof data in Rust.

Hello, World!

The classic first program. A document can be constructed from a string, file, or binary (Vec<u8>) (each with a format specifier). In this case, we are constructing a document from a Stof string.

The Stof "language" is just a format that gets parsed, just like any other in Stof. As such, it can be parsed into the document at any time, just like JSON or any other format.

use stof::SDoc;

fn main() {
    let mut doc = SDoc::src(r#"
        #[main]
        fn main() {
            pln('hello, world!');
        }
    "#, "stof").unwrap();

    let _ = doc.run(None);
}
> cargo run
hello, world!
GitHub repository
introduction and design