| Crates.io | obscura-client |
| lib.rs | obscura-client |
| version | 0.1.0 |
| created_at | 2025-02-25 22:39:56.294309+00 |
| updated_at | 2025-02-25 22:39:56.294309+00 |
| description | Rust Client for Obscura |
| homepage | |
| repository | https://github.com/cosmo9able/obscura-rust |
| max_upload_size | |
| id | 1569766 |
| size | 50,263 |
obscura-client LibraryThis guide will walk you through the steps to install and use the obscura-client library, and provide examples on how to handle errors and deserialize responses using serde_json and serde::Value.
First, add the obscura-client to your project by running the following command:
cargo add obscura-client
Make sure to import the necessary modules in your src/main.rs file:
use obscura_client::Client;
use obscura_client::ConfigMap;
use serde_json::Value;
Here's an example code snippet demonstrating how to use the Client and ConfigMap:
fn main() {
let url = "http://localhost:9797";
let token = "your token here";
let client = Client::new(url, token);
let config_map = ConfigMap::new(client);
// Reading a key
match config_map.read("your path here") {
Ok(Some(data)) => {
// Deserialize using serde_json::from_slice
match serde_json::from_slice::<Value>(&data) {
Ok(json) => println!("Deserialized JSON: {:?}", json),
Err(e) => eprintln!("Failed to deserialize JSON: {}", e),
}
}
Ok(None) => println!("Key not found"),
Err(e) => eprintln!("Error reading key: {}", e),
}
// Reading with prefix
match config_map.read_with_prefix("your path prefix here") {
Ok(Some(data)) => {
// Deserialize using serde_json::from_slice
match serde_json::from_slice::<Value>(&data) {
Ok(json) => println!("Deserialized JSON with prefix: {:?}", json),
Err(e) => eprintln!("Failed to deserialize JSON with prefix: {}", e),
}
}
Ok(None) => println!("No data found with prefix"),
Err(e) => eprintln!("Error reading with prefix: {}", e),
}
}
The example above includes error handling for:
Ensure that you handle these errors appropriately in your application to maintain robustness.
For more information, refer to the server project repository here.
This guide offers a basic understanding of using the obscura-client library. For more complex scenarios, consider exploring the library documentation and source code.