pub struct FeedSource { /* private fields */ }Expand description
Generation-aware wrapper: owns the generation number alongside the
backlog. The runtime persists generation via kevy-persist’s
feed sidecars; this type only holds the in-memory value.
use kevy_replicate::feed::{FeedPosition, FeedSource};
use kevy_replicate::source::ReplicationSource;
let mut feed = FeedSource::new(1, ReplicationSource::new(1 << 20));
let set = kevy_resp::Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]);
feed.source_mut().push_mutation(&set);
let mut cursor = FeedPosition::new(1, 0);
for frame in feed.read(cursor, 100)? {
cursor.offset = frame.offset + 1; // a consumer advances past what it applied
}
assert_eq!(cursor, feed.tail());Implementations§
Source§impl FeedSource
impl FeedSource
Sourcepub fn new(generation: u64, source: ReplicationSource) -> Self
pub fn new(generation: u64, source: ReplicationSource) -> Self
Wrap a backlog at an explicit generation (loaded from the feed sidecar at boot, or 1 for a fresh data dir).
use kevy_replicate::feed::{FeedPosition, FeedSource};
use kevy_replicate::source::ReplicationSource;
let feed = FeedSource::new(1, ReplicationSource::new(1 << 20));
assert_eq!(feed.tail(), FeedPosition::new(1, 0));Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Current generation.
use kevy_replicate::feed::FeedSource;
use kevy_replicate::source::ReplicationSource;
let mut feed = FeedSource::new(1, ReplicationSource::new(1 << 20));
assert_eq!(feed.generation(), 1);
feed.bump_generation();
assert_ne!(feed.generation(), 1);Sourcepub fn source(&self) -> &ReplicationSource
pub fn source(&self) -> &ReplicationSource
Access the wrapped backlog (push side + replica streaming keep
their existing ReplicationSource API).
use kevy_replicate::feed::FeedSource;
use kevy_replicate::source::ReplicationSource;
let feed = FeedSource::new(1, ReplicationSource::new(4096));
assert_eq!(feed.source().max_bytes(), 4096);
assert!(feed.source().is_empty());Sourcepub fn source_mut(&mut self) -> &mut ReplicationSource
pub fn source_mut(&mut self) -> &mut ReplicationSource
Mutable access for push_mutation / drop_up_to.
use kevy_replicate::feed::FeedSource;
use kevy_replicate::source::ReplicationSource;
let mut feed = FeedSource::new(1, ReplicationSource::new(1 << 20));
let set = kevy_resp::Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]);
assert_eq!(feed.source_mut().push_mutation(&set), 0);
feed.source_mut().drop_up_to(1); // every consumer has passed offset 0
assert!(feed.source().is_empty());Sourcepub fn bump_generation(&mut self)
pub fn bump_generation(&mut self)
Break continuity: draw a fresh generation and restart offsets at 0 (FLUSHALL / restore / promotion / unclean-boot policy). The backlog empties — frames from the old generation must never be served under the new one.
use kevy_replicate::feed::{FeedPosition, FeedSource};
use kevy_replicate::source::ReplicationSource;
let mut feed = FeedSource::new(1, ReplicationSource::new(1 << 20));
let set = kevy_resp::Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]);
feed.source_mut().push_mutation(&set);
feed.bump_generation();
assert_eq!(feed.tail(), FeedPosition::new(feed.generation(), 0));
assert!(feed.source().is_empty());Sourcepub fn tail(&self) -> FeedPosition
pub fn tail(&self) -> FeedPosition
The tail cursor: the current generation and the next offset — where a consumer resuming after a rebuild starts.
use kevy_replicate::feed::{FeedPosition, FeedSource};
use kevy_replicate::source::ReplicationSource;
let feed = FeedSource::new(5, ReplicationSource::new(1 << 20));
assert_eq!(feed.tail(), FeedPosition::new(5, 0));Sourcepub fn read(
&self,
at: FeedPosition,
max: usize,
) -> Result<Vec<FeedFrame<'_>>, FeedRead>
pub fn read( &self, at: FeedPosition, max: usize, ) -> Result<Vec<FeedFrame<'_>>, FeedRead>
Serve up to max frames at cursor at.
- Any OTHER generation →
Resync(the cursor belongs to a different offset history — uniqueness of(gen, offset)forbids serving it; generations are identities, not ordered). - Offset ahead of this generation’s stream →
Future. - Evicted offset →
Resyncwith the current tail.
use kevy_replicate::feed::{FeedPosition, FeedSource};
use kevy_replicate::source::ReplicationSource;
let mut feed = FeedSource::new(1, ReplicationSource::new(1 << 20));
let set = kevy_resp::Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]);
for _ in 0..5 {
feed.source_mut().push_mutation(&set);
}
let page = feed.read(FeedPosition::new(1, 0), 2)?; // at most 2 frames
assert_eq!(page.iter().map(|f| f.offset).collect::<Vec<_>>(), [0, 1]);