fabric_cache_client/lib.rs
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
//! # Fabric Client
//!
//! Client for interacting with a Fabric Cache server.
//!
//! - [crates.io homepage](https://crates.io/crates/fabric-cache-client)
//! - [documentation](https://docs.rs/fabric-cache-client/latest/fabric_cache_client/)
//!
//! Install
//! ---
//!
//! Use cargo CLI:
//! ```bash
//! cargo install fabric-client
//! ```
//!
//! Or manually add it into your Cargo.toml:
//! ```toml
//! [dependencies]
//! fabric-client = "0.1.3"
//! ```
//!
//! Usage
//! ---
//! For more thorough information, read the [docs](https://docs.rs/fabric-cache-client/latest/fabric_cache_client/).
//!
//! Simple example for a game leaderboard cache:
//! ```rust
//! use fabric_cache_client::FabricClient;
//! use serde::{Deserialize, Serialize};
//!
//! // Dummy data structures just for example
//! #[derive(Deserialize, Serialize, Debug)]
//! struct Leaderboard {
//! top_3_players: Vec<Player>,
//! highest_score: i32,
//! last_updated: String,
//! }
//! #[derive(Deserialize, Serialize, Debug, Clone)]
//! struct Player {
//! name: String,
//! score: i32,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), anyhow::Error> {
//! // Create a connection with the fabric-cache server
//! let mut cache = FabricClient::connect("127.0.0.1:8731").await.unwrap();
//!
//! // Some dummy data for the example
//! let players = vec![
//! Player {
//! name: "Leeroooy Jenkins".into(),
//! score: 2830,
//! },
//! Player {
//! name: "kinda l33t".into(),
//! score: 2315,
//! },
//! Player {
//! name: "Some Other Player".into(),
//! score: 1950,
//! },
//! ];
//! let leaderboard = Leaderboard {
//! top_3_players: players.clone(),
//! highest_score: players.first().map(|player| player.score).unwrap_or(0),
//! last_updated: "{current timestamp}".into(),
//! };
//!
//! // Insert the data into cache
//! cache.set("myGamesLeaderboard", &leaderboard).await?;
//!
//! // Retrieve the data from cache
//! let _leaderboard: Leaderboard = cache.get("myGamesLeaderboard").await?;
//!
//! // Update data in cache
//! let mut leaderboard: Leaderboard = cache.get("myGamesLeaderboard").await?;
//! leaderboard.top_3_players = vec![
//! Player {
//! name: "kinda l33t".into(),
//! score: 2910,
//! },
//! Player {
//! name: "Leeroooy Jenkins".into(),
//! score: 2830,
//! },
//! Player {
//! name: "Some Other Player".into(),
//! score: 2100,
//! },
//! ];
//! cache.set("myGamesLeaderboard", &leaderboard).await?;
//!
//! // Delete data in cache
//! cache.remove("myGamesLeaderboard").await?;
//!
//! Ok(())
//! }
//! ```
mod client;
mod error;
pub use client::FabricClient;
pub use error::Error;