HandoffReader

Struct HandoffReader 

Source
pub struct HandoffReader<T> { /* private fields */ }
Expand description

Reads locator handoff records from block storage.

Each poll call reads the block lease, deserializes the handoff state, and returns Some(state) if the generation has changed since the last successful poll.

§Fail-closed

If the block data is corrupt or deserialization fails, poll returns an error — never a stale or default value.

§Example

use grafos_locator::handoff::HandoffReader;
use grafos_locator::locator::QueueLocator;
use grafos_std::block::BlockBuilder;

let lease = BlockBuilder::new().acquire().unwrap();
let mut reader: HandoffReader<QueueLocator> = HandoffReader::new(lease);
match reader.poll() {
    Ok(Some(state)) => println!("new locator: {:?}", state.locator),
    Ok(None) => println!("no change"),
    Err(e) => println!("read error: {e}"),
}

Implementations§

Source§

impl<T: Serialize + DeserializeOwned + Clone> HandoffReader<T>

Source

pub fn new(block_lease: BlockLease) -> Self

Create a new handoff reader attached to the given block lease.

Source

pub fn poll(&mut self) -> Result<Option<HandoffState<T>>>

Poll the block storage for a new handoff state.

Returns Ok(Some(state)) if the generation has changed since the last successful poll, Ok(None) if unchanged, or Err on I/O or deserialization failure.

Source

pub fn changed(&self) -> bool

Returns true if the last poll returned a new generation.

Source

pub fn last_generation(&self) -> Option<FenceEpoch>

Returns the last generation seen by poll, if any.

Source

pub fn last_locator(&self) -> Option<&T>

Returns a reference to the last locator seen by poll, if any.

Auto Trait Implementations§

§

impl<T> Freeze for HandoffReader<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for HandoffReader<T>

§

impl<T> !Send for HandoffReader<T>

§

impl<T> !Sync for HandoffReader<T>

§

impl<T> Unpin for HandoffReader<T>
where T: Unpin,

§

impl<T> !UnwindSafe for HandoffReader<T>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.