Expand description
§AllSource Rust SDK
Official Rust client for the AllSource event store. Provides two clients:
QueryClient— reads from the Query Service (events, projections, streams)CoreClient— writes directly to Core (event ingestion, batch ingest)
Plus the EventFolder trait for reconstructing domain state from event streams.
§Quick Start
use allsource::{QueryClient, IngestEventInput};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), allsource::Error> {
let qs = QueryClient::new("http://localhost:3902", "your-api-key")?;
// Query events
let result = qs.query_events(
allsource::QueryEventsParams::new().entity_id("user-123").limit(10),
).await?;
for event in &result.events {
println!("{}: {}", event.event_type, event.timestamp);
}
Ok(())
}§Event Folding
use allsource::{Event, EventFolder, fold_events};
#[derive(Default)]
struct UserState {
email: Option<String>,
name: Option<String>,
active: bool,
}
impl EventFolder for UserState {
type State = Self;
fn apply(&mut self, event: &Event) -> bool {
match event.event_type.as_str() {
"user.created" => {
self.email = event.payload.get("email").and_then(|v| v.as_str()).map(String::from);
self.name = event.payload.get("name").and_then(|v| v.as_str()).map(String::from);
self.active = true;
true
}
"user.deactivated" => { self.active = false; true }
_ => false,
}
}
fn finalize(self) -> Option<Self::State> {
if self.email.is_some() { Some(self) } else { None }
}
}Re-exports§
pub use serde_json;
Macros§
- json
- Construct a
serde_json::Valuefrom a JSON literal.
Structs§
- Batch
Ingest Response - Response from batch ingesting events via Core.
- Circuit
Breaker - A circuit breaker that trips after consecutive failures.
- Client
Config - Full configuration for building a client.
- Core
Client - Client for AllSource Core (writes).
- Detect
Duplicates Response - Response from duplicate entity detection.
- Duplicate
Group - A group of entities that share the same payload field values (duplicates).
- Entity
Summary - Summary of a single entity returned by the list-entities endpoint.
- Event
- A stored event returned from AllSource.
- Health
Response - Health check response.
- Ingest
Event Input - An event to ingest into AllSource.
- Ingest
Response - Response from ingesting an event via Core.
- List
Entities Response - Response from listing entities.
- Projection
- A projection state.
- Projections
Response - Projections list response.
- Query
Client - Client for the AllSource Query Service (reads).
- Query
Events Params - Query parameters for filtering events. Uses builder pattern.
- Query
Events Response - Response from querying events.
- Retry
Config - Retry configuration for transient failures.
Enums§
Traits§
- Event
Folder - Trait for reconstructing domain state from an event stream.
Functions§
- fold_
events - Fold a sequence of events into domain state using an
EventFolder. - normalize_
event_ type - Normalize an event type to AllSource’s
lowercase.dot.separatedconvention.