Crates.io | datagen-rs-progress-plugin |
lib.rs | datagen-rs-progress-plugin |
version | 0.1.0 |
source | src |
created_at | 2023-09-26 10:14:41.69139 |
updated_at | 2023-09-26 10:14:41.69139 |
description | A progress plugin for datagen-rs |
homepage | |
repository | https://github.com/MarkusJx/datagen |
max_upload_size | |
id | 983476 |
size | 13,522 |
The progress plugin is a native plugin providing progress for the generation process.
The easiest way to use the progress plugin is to call ProgressPlugin::with_schema()
while providing a schema and a callback function:
use std::error::Error;
use datagen_rs::schema::schema_definition::Schema;
use progress_plugin::{PluginWithSchemaResult, ProgressPlugin};
use datagen_rs::util::helpers::generate_random_data;
fn generate(schema: Schema) -> Result<(), Box<dyn Error>> {
let PluginWithSchemaResult {
schema,
plugins,
} = ProgressPlugin::with_schema(schema, |current, total| {
println!("{} / {}", current, total);
})?;
let generated = generate_random_data(schema, Some(plugins))?;
println!("{}", generated);
}
The progress is calculated by first generating a list of array lengths for all arrays in the schema.
If the array length is a fixed value, the progress is calculated by multiplying the fixed value with the number of elements in the array. This is a recursive process, so if the array contains another array, the progress is calculated by multiplying the length of the array with the length of the inner array.
If the array length is a random value, the array length is calculated by generating a random value between the minimum and maximum value and storing this value in a list containing all array lengths. Then this value is multiplied with the number of elements in the array.
The number of elements in objects
and
anyOf
is also taken into account.