datagen-rs

Crates.iodatagen-rs
lib.rsdatagen-rs
version0.1.0
sourcesrc
created_at2023-09-25 15:38:27.206127
updated_at2023-09-25 15:38:27.206127
descriptionA random data generator written in rust
homepage
repositoryhttps://github.com/MarkusJx/datagen
max_upload_size
id982830
size154,443
Markus (MarkusJx)

documentation

README

datagen-rs

A Rust library for generating random data from a JSON schema.

Installation

Add the following to your Cargo.toml:

[dependencies]
datagen-rs = "0.1.0"

Usage

Generate data from a schema file

use datagen_rs::util::helpers::{generate_random_data, read_schema};

fn main() {
    let schema = read_schema("path/to/schema.json").unwrap();
    let data = generate_random_data(schema, None).unwrap();
    println!("{}", data);
}

Generate data from a schema string

use datagen_rs::util::helpers::{generate_random_data_from_str, read_schema};

fn main() {
    let schema: Schema = serde_json::from_str(r#"
    {
        "type": "string",
        "value": "test
    }
    "#).unwrap();
    let data = generate_random_data_from_str(&schema, None).unwrap();
    println!("{}", data);
}

Write the JSON schema to a file

use datagen_rs::util::helpers::write_json_schema;

fn main() {
    write_json_schema("path/to/schema.json").unwrap();
}

Features

Feature Description Depends on
plugin Enables loading plugins
native-plugin Enables loading plugins written in Rust plugin
serialize Enables serialization/deserialization for all structs using serde.
map-schema Enables data generation for several types serialize
generate Enables data generation for all types map-schema
schema Enables JSON schema generation using schemars serialize
all Enables all features native-plugin, generate, schema
Commit count: 20

cargo fmt