better-vdf 0.1.0

A VDF serialization file format using serde
Documentation
  • Coverage
  • 4.55%
    1 out of 22 items documented1 out of 1 items with examples
  • Size
  • Source code size: 39.79 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.68 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • MarkV43/better-vdf
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MarkV43

Since none of the VDF implementations I tried on crates.io worked for my intended purposes, I wrote my own.

Considering that VDF is a very badly documented data format, some data types (such as booleans) were implemented in a way that looks compatible with the data format, although they may not be 100% compatible with the original format. Vecs and bools are a couple of examples.

Usage

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug)]
struct Test {
    test: TestData,
}

#[derive(Serialize, Deserialize, Debug)]
struct TestData {
    name: String,
    list: Vec<TestObj>,
    map: HashMap<u64, i64>,
}

#[derive(Serialize, Deserialize, Debug)]
struct TestObj {
    obj: String,
    id: usize,
    weight: f32,
}

fn main() {
    let vdf = r#"
     "test"
     {
     	"name"		"Better VDF"
     	"list"
     	{
     		"0"
     		{
     			"obj"		"main_obj"
     			"id"		"19231"
     			"weight"		"12.9"
     		}
     		"1"
     		{
     			"obj"		"secondary_obj"
     			"id"		"381928"
     			"weight"		"5.12"
     		}
     	}
     	"map"
     	{
     		"228980"		"12318293"
     		"278319"		"-12393180"
     	}
     }
     "#;

    // Deserializing
    let test: Test = better_vdf::from_str(vdf).unwrap();

    println!("{test:#?}");

    // Serializing
    let serial = better_vdf::to_string(&test).unwrap();

    println!("{serial}");
}