Skip to content

Commit c42fb2a

Browse files
authored
Update README.md
1 parent 1da17cf commit c42fb2a

1 file changed

Lines changed: 22 additions & 29 deletions

File tree

README.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,37 @@ Add the following to your `Cargo.toml` file:
88

99
```toml: Cargo.toml
1010
[dependencies]
11-
easy_storage = "0.1.*"
11+
easy_storage = "0.2.*"
1212
```
1313

14-
## Example Usage
14+
## Example
1515

1616
```rust
17-
use serde::{Serialize, Deserialize};
18-
use storeable::{Storeable, Format, Error};
19-
use std::path::Path;
17+
use serde::{Deserialize, Serialize};
18+
use easy_storage::Storeable;
2019

21-
#[derive(Serialize, Deserialize, Debug, PartialEq)]
22-
struct MyData {
20+
#[derive(Debug, Serialize, Deserialize)]
21+
struct User {
2322
name: String,
24-
value: i32,
23+
email: String,
2524
}
2625

27-
impl Storeable<Path> for MyData {}
26+
impl<P: AsRef<std::path::Path>> Storeable<P> for User {}
2827

29-
fn main() -> Result<(), Error> {
30-
let data = MyData {
31-
name: "Example".to_string(),
32-
value: 42,
28+
fn main() {
29+
let user = User {
30+
name: "Alice".to_string(),
31+
email: "alice@alice.com".to_string(),
3332
};
34-
35-
let path = Path::new("data.json");
36-
37-
// Save to file
38-
data.save(path, true, Format::Json)?; // Creates a new file if it doesn't exist
39-
40-
// Load from file
41-
let loaded_data = MyData::load(path, Format::Json)?;
42-
43-
assert_eq!(data, loaded_data);
44-
println!("Loaded data: {:?}", loaded_data);
45-
46-
// Clean up the file (optional)
47-
std::fs::remove_file(path).unwrap();
48-
49-
Ok(())
33+
let save_path = std::env::current_dir().unwrap().join("test").join("user.toml");
34+
match user.save_by_extension(&save_path, true) {
35+
Ok(_) => println!("success."),
36+
Err(e) => println!("Error: {e}"),
37+
}
38+
39+
match User::load_by_extension(save_path) {
40+
Ok(s) => println!("{s:?}"),
41+
Err(e) => println!("Error: {e}"),
42+
}
5043
}
5144
```

0 commit comments

Comments
 (0)