19 releases
0.2.16 | Sep 24, 2024 |
---|---|
0.2.15 | Sep 20, 2024 |
0.1.15 | Aug 15, 2024 |
0.1.10 | Sep 20, 2024 |
0.1.7 | Jun 23, 2024 |
#42 in #light-weight
894 downloads per month
Used in wyre
13KB
166 lines
[wyre]
Welcome to wyre – the super lightweight serialization and communication crate that's so efficient, it practically serializes your data in its sleep. If you’ve ever thought, "Gee, I wish my serialization was as snappy as my sarcasm," then you're in the right place.
Features
- Binary Serialization: Because plain text is for chumps.
- JSON Serialization: For when you need to look sophisticated in front of your friends.
- RON Serialization: Not the guy from accounting, but Rusty Object Notation.
- MessagePack Serialization: Like moving to a tiny house – small but mighty.
- TOML Serialization: For those who like to keep their configs neat and tidy.
- Custom Derivation: Macro-based custom derive support for structs and enums, because writing boilerplate is so last decade.
Usage
First things first, add wyre
to your Cargo.toml
. This step is critical. Skipping it will result in... nothing working.
[dependencies]
wyre = "0.1.0"
Example
Here's a simple example to get you started. Even your grandma could follow this – if she’s into Rust, that is.
use wyre::{SerBin, DeBin, SerJson, DeJson, SerMsgPack, DeMsgPack};
#[derive(SerBin, DeBin, SerJson, DeJson, SerMsgPack, DeMsgPack, PartialEq, Debug)]
struct TestStruct {
a: u32,
b: String,
c: Vec<u8>,
}
fn main() {
let test_message = TestStruct {
a: 42,
b: "Hello, World!".to_string(),
c: vec![1, 2, 3, 4, 5],
};
// Binary Serialization
let serialized_bin = test_message.serialize_bin();
let deserialized_bin = TestStruct::deserialize_bin(&serialized_bin).unwrap();
assert_eq!(test_message, deserialized_bin);
println!("Binary serialization and deserialization succeeded! 🎉");
// JSON Serialization
let serialized_json = test_message.serialize_json();
let deserialized_json = TestStruct::deserialize_json(&serialized_json).unwrap();
assert_eq!(test_message, deserialized_json);
println!("JSON serialization and deserialization succeeded! 🎉");
// MessagePack Serialization
let serialized_wyre = test_message.pack();
let deserialized_wyre = TestStruct::depack(&serialized_wyre).unwrap();
assert_eq!(test_message, deserialized_wyre);
println!("MessagePack serialization and deserialization succeeded! 🎉");
}
License
This project is licensed under the MIT or Apache-2.0 license. Because sharing is caring.
And let's be honest, in today's world, every piece of code is just a beautifully mixed cocktail of copy-pasted snippets from Stack Overflow and GitHub.
Contributing
We welcome contributions! Please see our contributing guidelines. Don’t be shy – jump right in!
Dependencies
~3.5MB