Stdto provides a set of functional traits for conversion between various data representations.

Overview

Stdto

stdto provides a set of functional traits for conversion between various data representations.

CI Crates.io Licensed Twitter

| Examples | Docs | Latest Note |

stdto = "0.13.0"

Goal

As a blockchain developer who specializes in Rust, I often find it challenging to work with bytes, hashes, and JSON. The Rust ecosystem is decentralized and many popular crates are old and complex. This makes it difficult to find simple, well-abstracted solutions that are easy to understand. I created the Stdto crate to address this need. The goal of Stdto is to provide a standard library-like interface that makes it easy for users to work with and understand primitive data structures.

Features

default = ["derive", "serde", "bytes", "hash", "json", "yaml", "toml", "file", "hex"]
cargo add stdto  # [derive, serde, bytes, hash, json, yaml, toml, file, hex]
cargo add stdto --features "derive bytes" # [derive, serde, bytes]
cargo add stdto --features "derive hash" # [derive, serde, bytes, hash]
cargo add stdto --features "derive json" # [derive, serde, json]
cargo add stdto --features "derive yaml" # [derive, serde, yaml]
cargo add stdto --features "derive toml" # [derive, serde, toml]
cargo add stdto --features "derive file" # [derive, serde, json, yaml, toml]
cargo add stdto --features "derive hex" # [derive, hex]

Examples

use stdto::prelude::*;
// #[stdto::bytes(endian = "little")]
#[stdto::bytes]
struct Test {
    a: u32,
    b: String,
    c: [u8; 32],
    d: Vec<u8>,
    e: BTreeMap<String, f64>,
}

let bytes = Test { .. }.to_bytes();
let test = Test::from_bytes(bytes);
// Test::try_from_bytes(bytes).unwrap();
#[stdto::bytes]
#[stdto::hash]
struct Test {
    ...
}

let hash = test.to_hash::<sha2::Sha256>();
// Any digest crate implemented hasher type
#[stdto::json]
// #[stdto::yaml]
// #[stdto::toml]
struct Test {
    ...
}

let json = test.to_json();
let test = Test::from_json(json);
// Test::try_from_json(json).unwrap();

// let yaml = test.to_yaml();
// let test = Test::from_yaml(yaml);
// let toml = test.to_toml();
// let test = Test::from_toml(toml);
// Any AsRef<[u8]> or AsBytes implemented to hex

let hex = bytes.to_hex();
let hex = hash.to_hex();
let bytes = Vec::<u8>::from_hex(hex);
// Vec::<u8>::try_from_hex(hex).unwrap();

let mut arr = [0u8; 32];
arr.copy_from_hex(hex);
// Any AsRef<[u8]> or AsBytes implemented <-> String, &str

let arr = [72, 105, 77, 111, 109];
let s1 = arr.into_string(); // .try_into_string().unwrap();
let bytes = s1.to_bytes();
let s2 = bytes.as_str(); // .try_as_str().unwrap();

assert_eq!(s1, s2);
You might also like...
Femtorinth is a library to interact with a sub-set of the Modrinth API.

Femtorinth Femtorinth is a rust library to interact with a sub-set of the Modrinth api, it only includes the api calls that don't need auth (a.k.a onl

A set of utilities to better enable polymorphic behavior in Rust

Polymorph A set of utilities to better enable polymorphic behavior in Rust. Introduction Rust is a wonderful language, with a strong emphasis on fast,

A set of bison skeleton files that can be used to generate a Bison grammar that is written in Rust.

rust-bison-skeleton A set of bison skeleton files that can be used to generate a Bison grammar that is written in Rust. Technically it's more like a B

Output the individual word-count statistics from a set of files
Output the individual word-count statistics from a set of files

Output the individual word-count statistics from a set of files, or generate a curated word list

Convert Juniper configurations to 'set-style'

JCC: Juniper Config Converter Convert Juniper configurations. Takes a Juniper configuration as displayed using show configuration and transforms it to

Get a diff between two OpenAPI descriptions.

Get the difference between two OpenAPI descriptions.

Easy switch between AWS Profiles and Regions
Easy switch between AWS Profiles and Regions

AWSP - CLI To Manage your AWS Profiles! AWSP provides an interactive terminal to interact with your AWS Profiles. The aim of this project is to make i

This crate bridges between gstreamer and tracing ecosystems.

This crate provides a bridge between gstreamer and the tracing ecosystem. The goal is to allow Rust applications utilizing GStreamer to better integra

Simple interoperability between C++ coroutines and asynchronous Rust

cxx-async Overview cxx-async is a Rust crate that extends the cxx library to provide seamless interoperability between asynchronous Rust code using as

Releases(v0.13.0)
  • v0.13.0(Dec 26, 2022)

    Improved

    • Default exported ToStringForBytes trait.
    • Refactor ToHex.
    • Removed the feature bytes in the hex feature. hex is now independent. hex = [].
    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Dec 22, 2022)

    BREAKING CHANGES

    • DebugBytes and DebugHex, along with all other future debug printing traits, are now printing without including #.

    Added

    • Added DebugHash and #[debug(hasher = ...)].
    Source code(tar.gz)
    Source code(zip)
  • v0.11.0(Dec 21, 2022)

  • v0.10.0(Dec 21, 2022)

  • v0.9.0(Dec 21, 2022)

    BREAKING CHANGES

    • Some of methods in the ToJson.

    Added

    • Added features yaml and toml and file.
    • Added ToYaml and stdto::yaml conversion.
    • Added ToToml and stdto::toml conversion.
    Source code(tar.gz)
    Source code(zip)
  • v0.8.0(Dec 21, 2022)

  • v0.7.0(Dec 20, 2022)

    BREAKING CHANGES

    • features in Cargo.toml.

    Added

    • Added AsBytes for general purpose trait.
    • Refactor ToHex and ToStringForRef.
    • Renamed ToStringForRef to ToStringForBytes.
    • Added DebugBytes derive macro for debugging with automatic bytes representation when the DebugBytes is derived.
    • Added DebugHex derive macro for debugging with automatic hexadecimal string representation when the DebugHex is derived.
    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Dec 14, 2022)

    Added

    • Added ToJson and stdto::json conversion.
    • Added ToStringForRef functional trait for converting between AsRef<[u8]> and String or &str.

    Improved

    • No need to implement #[stdo::serde] anymore. Also no need to concern about conflicting #[stdto::serde] and #[stdto::bytes] and #[stdto::json].
    • Changed all of ..from_bytes_..<'a>(..: &'a [u8]).. to ..from_bytes_..(..: impl AsRef<[u8]>)...
    • Added as_bytes(), into_bytes() in the ToBytesForRef trait.

    Released by @just-do-halee.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Dec 13, 2022)

    Added

    • Added const fn ToBytesOptions::default().
    • Added ToBytesForRef functional trait for creating Vec<u8> from AsRef<[u8]>.

    Improved

    • Refactor Cargo.toml: dependency features.
    • It's okay to derive ToBytes without serde::Serialize. But if you want to use the methods of de/serialization, you should derive serde::Serialize or serde::Deserialize.
    • ..from_hex(..: impl AsRef<str>) to ..from_hex(..: impl AsRef<[u8]>).

    Released by @just-do-halee.

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Dec 13, 2022)

  • v0.3.0(Dec 12, 2022)

    BREAKING CHANGES

    • Renamed the methods in ToBytes and Added the const ToBytesOptions.
    • Re-design [features].

    Added

    • Added an attribute #[stdto::bytes(endian = "...")]. (little/big/native)
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Dec 10, 2022)

Owner
Doha Lee
I will change the world.
Doha Lee
Various extention traits for providing asynchronous higher-order functions

async-hofs Various extention traits for providing asynchronous higher-order functions. // This won't make any name conflicts since all imports inside

かわえもん 5 Jun 28, 2022
hy-rs, pronounced high rise, provides a unified and portable to the hypervisor APIs provided by various platforms.

Introduction The hy-rs crate, pronounced as high rise, provides a unified and portable interface to the hypervisor APIs provided by various platforms.

S.J.R. van Schaik 12 Nov 1, 2022
A lean, minimal, and stable set of types for color interoperation between crates in Rust.

This library provides a lean, minimal, and stable set of types for color interoperation between crates in Rust. Its goal is to serve the same function that mint provides for (linear algebra) math types.

Gray Olson 16 Sep 21, 2022
miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

Kat Marchán 1.2k Jan 1, 2023
Annotation to easily define ad-hoc / one-shot extension traits

Annotation to easily define ad-hoc / one-shot extension traits

Daniel Henry-Mantilla 2 Apr 19, 2022
Async `TryFrom/TryInto` traits

async-convert Async TryFrom/TryInto traits API Docs | Releases | Contributing Installation $ cargo add async-convert Safety This crate uses #![deny(un

Yosh 4 Mar 4, 2022
Rust crate for creating filters with DirectX shaders. Includes Scale, Color conversion using DirectX api.

DxFilter Scale and ColorConversion done with DirectX filters. You can also create your own filters with the provided api. Crate contains various tools

null 4 Aug 13, 2022
Functional testing framework for AVR binaries, powered by simavr.

Functional testing framework for AVR binaries, powered by simavr. tl;dr get your microcontroller's firmware black-box-tested in seconds!

Patryk Wychowaniec 14 Nov 16, 2022
A plugin for Devzat that can tell the time at various timezones.

Devzat Time Teller On Devzat, people come from all around the time. It is sometime hard to know what time it is for other peoples. This plugin let you

Maxime Bouillot 3 Jun 24, 2022
Rusty Armor Builds - Monster Hunter Rise Armor Set Creation Tool

RAB Rusty Armor Builds - Monster Hunter Rise Armor Set Creation Tool Armor files used by RAB

null 28 Oct 3, 2022