Crates.io | samplify-rs |
lib.rs | samplify-rs |
version | 0.1.7 |
source | src |
created_at | 2024-10-14 15:37:53.953479 |
updated_at | 2024-11-09 05:32:24.264709 |
description | A procedural macro to generate sample data for Rust structs. |
homepage | https://github.com/Open-Payments/samplify-rs |
repository | https://github.com/Open-Payments/samplify-rs |
max_upload_size | |
id | 1408425 |
size | 44,191 |
A Powerful and Flexible Sample Data Generator for Rust
samplify-rs is a Rust library designed to simplify the process of generating sample data for testing, prototyping, and development purposes. Leveraging Rust’s powerful procedural macros and conditional compilation features, samplify-rs allows you to automatically generate realistic and customizable sample instances of your data structures without polluting your production code.
Add the following to your Cargo.toml:
[dependencies]
samplify-rs = "0.1.0"
use samplify_rs::Sampleable;
Use #[cfg_attr(feature = "sample", derive(Sampleable))]
on your structs and enums.
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "sample", derive(Sampleable))]
struct PaymentInstruction {
currency: String,
amount: f64,
}
use samplify_rs::Sampleable;
use serde::{Deserialize, Serialize};
use serde_json;
#[derive(Debug, Serialize, Deserialize, Sampleable)]
struct PaymentInstruction {
currency: String,
amount: f64,
}
fn main() -> Result<(), String> {
let config_json = r#"
{
"amount": [10.0, 1000.0],
"currency": ["USD", "EUR", "GBP"]
}
"#;
let config_map: serde_json::Map<String, serde_json::Value> = serde_json::from_str(config_json).map_err(|e| e.to_string())?;
let sample_payment = PaymentInstruction::sample(&config_map)?;
println!("{:?}", sample_payment);
Ok(())
}