DataStruct
DataStruct is a Rust library that provides a set of data structures and utilities for working with binary data, JSON, and other formats. It includes a Binary
struct for handling binary data, a DValue
enum for representing various data types, and a parser for parsing data from strings.
Features
- Binary Data Handling: The
Binary
struct allows you to work with binary data, including encoding and decoding to and from base64 strings. - Data Value Representation: The
DValue
enum represents various data types, including strings, numbers, booleans, lists, dictionaries, and tuples. - JSON Serialization: DataStruct provides JSON serialization and deserialization for the
DValue
enum. - Parser: The library includes a parser for parsing data from strings into
DValue
instances.
Usage
Add the following to your Cargo.toml
:
[]
= "0.1.0"
Binary Utility
use Binary;
use PathBuf;
// Create a new Binary instance from a vector of bytes
let binary = new;
// Read binary data from a file
let path = from;
let binary_from_file = from_file?;
// Decode base64-encoded string to binary
let base64_string = "SGVsbG8gd29ybGQ=";
let binary_from_b64 = from_b64?;
DValue Enum
use DValue;
use HashMap;
// Create different DValue instances
let string_value = String;
let number_value = Number;
let boolean_value = Boolean;
let list_value = List;
let dict_value = Dict;
// Convert a DValue instance to JSON
let json_string = string_value.to_json;
// Parse a string to a DValue instance
let parsed_value = from;
let size = string_value.size;
License
MIT License