Skip to main content

FeedSource

Struct FeedSource 

Source
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

Source

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));
Source

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);
Source

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());
Source

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());
Source

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());
Source

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));
Source

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 → Resync with 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]);

Trait Implementations§

Source§

impl Debug for FeedSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.