Nexus
Ordering
Ordering policies in Nexus — pluggable comparators and per-view ordering rules across multi-strand inputs.
Purpose
Multi-strand ordered views with governance, custom ordering, strand input stats, and materialized projections.
This page follows the real source shape for Nexus and explains the workflow a developer is likely to use first.
Developer workflow
Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.
Primary types to know
AllowAllPolicy— models/nexus/src/governance.rsApprovalRecord— models/nexus/src/governance.rsCustomOrdering— models/nexus/src/ordering.rsGovernancePolicy— models/nexus/src/governance.rsGovernanceRules— models/nexus/src/governance.rsIndexOrdering— models/nexus/src/ordering.rsInputStrand— models/nexus/src/strand_input.rsMemoryView— models/nexus/src/view.rsNexus— models/nexus/src/nexus.rsNexusConfig— models/nexus/src/config.rsNexusCursor— models/nexus/src/view.rsPage— models/nexus/src/view.rs
Example shape
use nexus::{CustomOrdering, OrderingStrategy, TimestampOrdering, UnorderedEntry};
use std::time::{Duration, SystemTime};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Hand-craft entries from two notional writers. In production these come
// from InputStrand replay; here we build them inline to demonstrate ordering.
let base = SystemTime::now();
let entries = vec![
UnorderedEntry {
source_agent: "did:l1fe:writer-a".into(),
source_index: 0,
data: b"first-from-a".to_vec(),
timestamp: base + Duration::from_millis(5),
metadata: None,
},
UnorderedEntry {
source_agent: "did:l1fe:writer-b".into(),
source_index: 0,
data: b"first-from-b".to_vec(),
timestamp: base + Duration::from_millis(2),
metadata: None,
},
];
// TimestampOrdering sorts by wall-clock time, breaking ties stably by agent DID.
let timestamped = TimestampOrdering::with_stable_sort(true);
let view = timestamped.order(entries.clone());
// CustomOrdering lets callers plug in any comparator — here, lexicographic by data.
let lexicographic = CustomOrdering::new("lex".to_string(), |a: &UnorderedEntry, b: &UnorderedEntry| {
a.data.cmp(&b.data)
});
let lex_view = lexicographic.order(entries);
println!(
"ts_strategy={} ts_first={:?} lex_first={:?}",
timestamped.name(),
std::str::from_utf8(&view[0].data).ok(),
std::str::from_utf8(&lex_view[0].data).ok(),
);
Ok(())
}