shori
is a flexible data transformation and parsing toolkit for Rust.
It provides the #[derive(Parser)]
macro, which automatically implements conversions for your structs—supporting formats like JSON, TOML, bincode, and common smart pointers and containers like Arc
, Mutex
, and Box
.
Designed for ergonomic and type-safe data manipulation.
#[derive(Parser)]
implements:.parse().json()
.toml()
.bin()
.map()
.from()
,.from_value()
- Supports conversion from and to:
String
,Vec<u8>
,serde_json::Value
,toml::Value
,HashMap<String, Value>
- Wrappers:
Box
,Arc
,Mutex
,RefCell
,OnceCell
,UnsafeCell
,tokio::sync::Mutex
,Vec<T>
cargo add shori
Basic Example
use kenzu::Builder;
use serde::{Deserialize, Serialize};
use shori::Parser;
#[derive(
Builder,
Default,
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
bincode::Encode,
bincode::Decode,
Parser,
)]
pub struct User {
pub id: String,
#[set(value = "name")]
pub name: String,
pub password: String,
#[set(value = "email@example.com")]
pub email: String,
#[set(value = 18)]
pub age: u8,
pub gender: String,
}
fn parse_toml() {
let user_parse = User::new()
.id("123e4567-e89b-12d3-a456-426614174000")
.name("John Doe")
.password("123")
.email("john@example.com")
.age(25)
.gender("M")
.build()
.unwrap()
.parse()
.toml()
.unwrap();
let toml_val = user_parse.get();
let recovered = user_parse.from_value(&toml_val).unwrap();
assert_eq!(recovered.name, "John Doe");
let from = user_parse.from().unwrap();
assert_eq!(from.email, "john@example.com");
}
fn parse_box() {
let user = User::new()
.id("123e4567-e89b-12d3-a456-426614174000")
.name("John Doe")
.password("password123")
.email("johndoe@example.com")
.age(25)
.gender("F")
.build()
.unwrap()
.parse()
.boxed()
.get();
assert_eq!(user.name, "John Doe");
}