
bridge.rs
Prima bridge pattern implementation for rust
Example
use prima_bridge::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct DeserializableData {
test: String
}
fn bridge() -> &'static Bridge {
static BRIDGE: OnceCell<Bridge> = OnceCell::new();
BRIDGE.get_or_init(|| Bridge::new("https://prima.it/api"))
}
pub fn fetch_data() -> YourResult<DeserializableData> {
Request::get(bridge())
.send()?
.get_data(&["nested", "selector"])? }
To understand this example you should know:
- once_cell library providing the cell type
- Rust error handling to use ? and convert it to a custom error type. See for example thiserror