quick_kv/
lib.rs

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