fabric_cache_client/lib.rs
1//! # Fabric Client
2//!
3//! Client for interacting with a Fabric Cache server.
4//!
5//! - [crates.io homepage](https://crates.io/crates/fabric-cache-client)
6//! - [documentation](https://docs.rs/fabric-cache-client/latest/fabric_cache_client/)
7//!
8//! Install
9//! ---
10//!
11//! Use cargo CLI:
12//! ```bash
13//! cargo install fabric-client
14//! ```
15//!
16//! Or manually add it into your Cargo.toml:
17//! ```toml
18//! [dependencies]
19//! fabric-client = "0.1.3"
20//! ```
21//!
22//! Usage
23//! ---
24//! For more thorough information, read the [docs](https://docs.rs/fabric-cache-client/latest/fabric_cache_client/).
25//!
26//! Simple example for a game leaderboard cache:
27//! ```rust
28//! use fabric_cache_client::FabricClient;
29//! use serde::{Deserialize, Serialize};
30//!
31//! // Dummy data structures just for example
32//! #[derive(Deserialize, Serialize, Debug)]
33//! struct Leaderboard {
34//! top_3_players: Vec<Player>,
35//! highest_score: i32,
36//! last_updated: String,
37//! }
38//! #[derive(Deserialize, Serialize, Debug, Clone)]
39//! struct Player {
40//! name: String,
41//! score: i32,
42//! }
43//!
44//! #[tokio::main]
45//! async fn main() -> Result<(), anyhow::Error> {
46//! // Create a connection with the fabric-cache server
47//! let mut cache = FabricClient::connect("127.0.0.1:8731").await.unwrap();
48//!
49//! // Some dummy data for the example
50//! let players = vec![
51//! Player {
52//! name: "Leeroooy Jenkins".into(),
53//! score: 2830,
54//! },
55//! Player {
56//! name: "kinda l33t".into(),
57//! score: 2315,
58//! },
59//! Player {
60//! name: "Some Other Player".into(),
61//! score: 1950,
62//! },
63//! ];
64//! let leaderboard = Leaderboard {
65//! top_3_players: players.clone(),
66//! highest_score: players.first().map(|player| player.score).unwrap_or(0),
67//! last_updated: "{current timestamp}".into(),
68//! };
69//!
70//! // Insert the data into cache
71//! cache.set("myGamesLeaderboard", &leaderboard).await?;
72//!
73//! // Retrieve the data from cache
74//! let _leaderboard: Leaderboard = cache.get("myGamesLeaderboard").await?;
75//!
76//! // Update data in cache
77//! let mut leaderboard: Leaderboard = cache.get("myGamesLeaderboard").await?;
78//! leaderboard.top_3_players = vec![
79//! Player {
80//! name: "kinda l33t".into(),
81//! score: 2910,
82//! },
83//! Player {
84//! name: "Leeroooy Jenkins".into(),
85//! score: 2830,
86//! },
87//! Player {
88//! name: "Some Other Player".into(),
89//! score: 2100,
90//! },
91//! ];
92//! cache.set("myGamesLeaderboard", &leaderboard).await?;
93//!
94//! // Delete data in cache
95//! cache.remove("myGamesLeaderboard").await?;
96//!
97//! Ok(())
98//! }
99//! ```
100
101mod client;
102mod error;
103
104pub use client::FabricClient;
105pub use error::Error;