1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! QuickKV is a simple, fast, and easy to use key-value store.
//!
//! # Features
//!
//! - Simple API
//! - Built-in Logging
//! - I/O Caching
//! - CLI tool (Beta)
//!
//! ## Useful Links
//!
//! [Documentation] | [Crates.io] | [Github]
//!
//! ## Examples
//!
//! ```rust
//! use std::io;
//! use quick_kv::prelude::*;
//! use rand::Rng;
//!
//! #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
//! struct GuessingGame
//! {
//! tries: u32,
//! incorrect_guesses: Vec<u32>,
//! }
//!
//! fn main() -> anyhow::Result<()>
//! {
//! let mut client = QuickClient::<GuessingGame>::new(ClientConfig::default());
//! // First, we create a new game.
//! let game = GuessingGame {
//! tries: 0,
//! incorrect_guesses: vec![],
//! };
//!
//! // Set the game in the client.
//! client.set("game", game.clone())?;
//!
//! println!("Welcome to the Number Guessing Game!");
//! println!("You have 5 attempts to guess a number between 1 and 50.");
//!
//! let secret_number = rand::thread_rng().gen_range(1..50);
//!
//! loop {
//! let game_state = client.get("game")?.unwrap();
//! let remaining_attempts = 5 - game_state.tries;
//! if remaining_attempts == 0 {
//! println!("Sorry, you have lost the game!");
//! println!("The secret number was {}.", secret_number);
//! client.delete("game")?;
//! break;
//! }
//! println!("Attempts left: {}", remaining_attempts);
//! println!("Please input your guess:");
//!
//! let mut guess = String::new();
//!
//! io::stdin().read_line(&mut guess).expect("Failed to read line");
//!
//! if guess.trim().to_lowercase() == "quit" {
//! println!("Thanks for playing!");
//! break;
//! }
//! let guess: u32 = match guess.trim().parse() {
//! Ok(num) => num,
//! Err(_) => {
//! println!("Please enter a valid number!");
//! continue;
//! }
//! };
//!
//! if guess < 1 || guess > 50 {
//! println!("The secret number is between 1 and 50.");
//! continue;
//! }
//!
//! if guess == secret_number {
//! println!("Congratulations! You guessed the correct number!");
//! client.delete("game")?;
//! break;
//! } else if guess < secret_number {
//! println!("Sorry, your guess was too low. Try a higher number!");
//! } else {
//! println!("Sorry, your guess was too high. Try a lower number!");
//! }
//!
//! let updated_game = GuessingGame {
//! tries: game_state.tries + 1,
//! incorrect_guesses: game_state.incorrect_guesses.clone(),
//! };
//!
//! client.update("game", updated_game, None)?;
//! }
//! Ok(())
//! }
//! ```
//!
//! More examples can be found in the [examples] directory.
//!
//! [examples]: https://github.com/ThatGuyJamal/quick-kv/tree/master/examples
//!
//! [Documentation]: https://docs.rs/quick-kv
//! [Crates.io]: https://crates.io/crates/quick-kv
//! [Github]: https://github.com/ThatGuyJamal/quick-kv