Skip to content

Commit 0b71fac

Browse files
committed
Release 0.2.0
1 parent 68f20e9 commit 0b71fac

File tree

12 files changed

+359
-254
lines changed

12 files changed

+359
-254
lines changed

Cargo.toml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "bytebox"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2021"
5-
description = "Easy and performant data storage inspired by Flutter's shared_preferences."
6-
keywords = ["storage", "msgpack", "serde"]
5+
description = "High performance and secure data storage solution."
6+
keywords = ["storage", "config", "serde"]
77
categories = ["config", "encoding"]
88
license = "MIT OR Apache-2.0"
99
readme = "README.md"
@@ -12,21 +12,22 @@ homepage = "https://github.com/drafteddev/bytebox"
1212
documentation = "https://docs.rs/bytebox"
1313

1414
[dependencies]
15-
dirs = { version = "5.0.1", optional = true }
16-
serde = { version = "1", features = ["derive"] }
17-
rmp-serde = "1.1.2"
18-
bevy = { version = "0.12.1", optional = true, default-features = false }
15+
bitcode = { version = "0.6.9", features = ["serde"] }
16+
serde = { version = "1.0", features = ["derive"] }
17+
chacha20poly1305 = "0.10.1"
1918

20-
[dev-dependencies]
21-
bevy = { version = "0.12.1", default-features = false }
19+
[target.'cfg(target_os = "linux")'.dependencies]
20+
keyring = { version = "3.6.3", features = ["linux-native"] }
21+
22+
[target.'cfg(target_os = "macos")'.dependencies]
23+
keyring = { version = "3.6.3", features = ["apple-native"] }
24+
25+
[target.'cfg(target_os = "windows")'.dependencies]
26+
keyring = { version = "3.6.3", features = ["windows-native"] }
2227

2328
[features]
24-
default = ["path"]
25-
# Contains common functionality for building app data paths.
26-
path = ["dep:dirs"]
27-
bevy = ["dep:bevy"]
29+
default = []
2830

2931
[[example]]
3032
name = "hello_world"
3133
path = "examples/hello_world.rs"
32-
required-features = ["path"]

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
# ByteBox 📦
22

3-
ByteBox is an easy and performant data storage solution based on MessagePack. It provides a simple interface for storing
4-
and retrieving data in a compact format, making it efficient for various applications.
3+
**ByteBox is an easy and performant data storage solution. It provides a way to read and write data, optionally in a secure format.**
54

65
## Features ✨
76

8-
- **Compact Storage:** ByteBox uses the MessagePack format, ensuring a compact representation of your data.
9-
- **Easy Integration:** Simple API for storing and retrieving data with just a few method calls.
10-
- **Efficient Serialization:** Optimized serialization and deserialization using the rmp_serde library.
7+
- **Fast** - Serialization uses [bitcode](https://crates.io/crates/bitcode) for maximum decoding and encoding performance.
8+
- **Ease-of-use** - Use [serde](https://crates.io/crates/serde) and a super-easy API to store and retrieve your data.
9+
- **Secure** - Secure your data using the XChaCha20Poly1305 algorithm without the hassle of storing and retrieving encryption keys manually.
1110

1211
## Getting Started 🚀
1312

1413
To use ByteBox in your Rust project, run: ``cargo add bytebox`` or just add the latest version to your `Cargo.toml`.
1514

1615
## Examples 📝
1716
- [Hello World](examples/hello_world.rs)
18-
19-
## Bevy Integration
20-
You can easily use ByteBox in your Bevy app by adding the `bevy` feature and registering the `ByteboxPlugin` plugin.
21-
22-
Add your boxes by calling `ByteboxPlugin::new().with(my_box)` and access your boxes via the `Res<ByteBox>` type in your systems.

examples/hello_world.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use bytebox::{byte_box::ByteBox, Deserialize, Serialize};
1+
use std::path::PathBuf;
22

3-
static APP_NAME: &str = "hello_world";
4-
static BOX_NAME: &str = "my awesome box";
3+
use bytebox::ByteBox;
4+
use serde::{Deserialize, Serialize};
55

66
#[derive(Serialize, Deserialize)]
77
struct MyBox {
@@ -11,34 +11,37 @@ struct MyBox {
1111
age: i32,
1212
}
1313

14-
#[cfg(feature = "default")]
14+
impl ByteBox<true> for MyBox {
15+
fn path(&self) -> PathBuf {
16+
PathBuf::from("my_box.bin")
17+
}
18+
}
19+
1520
fn main() {
16-
let bytebox = ByteBox::default(APP_NAME).expect("Could not create ByteBox");
17-
18-
// write data container to file
19-
bytebox
20-
.set(
21-
BOX_NAME,
22-
&MyBox {
23-
special_number: 12,
24-
greet: true,
25-
name: "John".to_string(),
26-
age: 19,
27-
},
28-
)
29-
.expect("Could not write to ByteBox");
30-
31-
// retrieve data container
32-
let my_box = bytebox
33-
.get::<MyBox>(BOX_NAME)
34-
.expect("Could not read from ByteBox");
35-
36-
// cleanup bytebox
37-
bytebox.delete();
38-
39-
if my_box.greet {
40-
println!("Hello, {}! You are {} years old.", my_box.name, my_box.age);
21+
let my_box = MyBox {
22+
special_number: 12,
23+
greet: true,
24+
name: "John".to_string(),
25+
age: 19,
26+
};
27+
28+
my_box.save().expect("Could not save ByteBox");
29+
30+
let mut loaded_box = MyBox {
31+
special_number: 0,
32+
greet: false,
33+
name: String::new(),
34+
age: 0,
35+
};
36+
37+
loaded_box.load().expect("Could not load ByteBox");
38+
39+
if loaded_box.greet {
40+
println!(
41+
"Hello, {}! You are {} years old.",
42+
loaded_box.name, loaded_box.age
43+
);
4144
}
4245

43-
println!("The special number is {}", my_box.special_number);
46+
println!("The special number is {}", loaded_box.special_number);
4447
}

my_box.bin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�A"��眇e,�s�LxRZ��mŦ�ϭ(y7�&-��0�%O{���y�7W

src/bevy.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/byte_box.rs

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/error.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::fmt::{Display, Formatter};
2+
3+
/// An error that can occur while operating on a bytebox.
4+
#[derive(Debug)]
5+
pub enum Error {
6+
/// An I/O error.
7+
Io(std::io::Error),
8+
/// A Serde error.
9+
Serde(bitcode::Error),
10+
/// A cipher error.
11+
Cipher(chacha20poly1305::Error),
12+
/// A keyring error.
13+
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
14+
KeyRing(keyring::Error),
15+
}
16+
17+
impl Display for Error {
18+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19+
match self {
20+
Error::Io(e) => write!(f, "IO error: {}", e),
21+
Error::Serde(e) => write!(f, "Serde error: {}", e),
22+
Error::Cipher(e) => write!(f, "Cipher error: {}", e),
23+
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
24+
Error::KeyRing(e) => write!(f, "KeyRing error: {}", e),
25+
}
26+
}
27+
}
28+
29+
impl std::error::Error for Error {}
30+
31+
impl From<std::io::Error> for Error {
32+
fn from(e: std::io::Error) -> Self {
33+
Error::Io(e)
34+
}
35+
}
36+
37+
impl From<bitcode::Error> for Error {
38+
fn from(e: bitcode::Error) -> Self {
39+
Error::Serde(e)
40+
}
41+
}
42+
43+
impl From<chacha20poly1305::Error> for Error {
44+
fn from(e: chacha20poly1305::Error) -> Self {
45+
Error::Cipher(e)
46+
}
47+
}
48+
49+
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
50+
impl From<keyring::Error> for Error {
51+
fn from(e: keyring::Error) -> Self {
52+
Error::KeyRing(e)
53+
}
54+
}

0 commit comments

Comments
 (0)