Exports
Export data from Stof.
Stof can export any format for which it has an implementation. It is up to each format implementation to decide how the export works - most are lossy (JSON, for example, can only export fields). Some are binary only, some use directories (like "docs"), and some only support a specific field, where content is expected to live.
Formats are extensible and replaceable, though, so feel free to create your own! And share with the Stof community so that everyone can benefit.
Std.stringify & Std.blobify
The most common way to export data is by using the Standard Library (Std). In addition to Std.stringify(..)
(which might already feel familiar), the library also offers Std.blobify(..)
, which uses the binary_export
function of your desired (and loaded) format implementation.
Example
#[main]
fn main() {
const object = new {
a: "hello",
b: 42,
c: true,
};
const json: str = stringify("json", object); // string export
const bytes: blob = blobify("json", object); // binary export
assert_eq(json, '{"a":"hello","b":42,"c":true}');
assert_eq(bytes as str, json);
}
Last updated
Was this helpful?