pub struct AckPolicy {
pub quorum: usize,
pub timeout: Duration,
}Expand description
Policy controlling how many peer acks satisfy a put_quorum request.
Construct via the associated functions (any,
for_peer_count, all) which
pick sensible default timeouts. Override the timeout via
with_timeout.
§Examples
// Gun.js default — first ack wins, 9s timeout
let p = AckPolicy::any();
// Majority of 5 peers — 3 acks needed, 9s timeout
let p = AckPolicy::for_peer_count(5);
// All fanned-out peers must ack
let p = AckPolicy::all();
// Any ack, but with a tighter 2s deadline
let p = AckPolicy::any().with_timeout(Duration::from_secs(2));Fields§
§quorum: usizeNumber of peer acks required to satisfy the policy.
1 = any, usize::MAX = all (effective bound: fanned-out peer count).
timeout: DurationMaximum time to wait before the request resolves with Err.
Implementations§
Source§impl AckPolicy
impl AckPolicy
Sourcepub fn any() -> Self
pub fn any() -> Self
“First ack wins” policy with the Gun.js default 9-second timeout.
This matches the behaviour of Gun.js’s ask when no quorum is
specified — the requester resolves as soon as any peer or the
local storage commits the put.
Sourcepub fn for_peer_count(peer_count: usize) -> Self
pub fn for_peer_count(peer_count: usize) -> Self
Majority quorum: ⌈N/2⌉ of peer_count peers must ack.
Uses the Raft/Dynamo-style majority to balance availability against
consistency. For peer_count == 0 or 1, falls back to
any since majority is undefined for trivial peer sets.
§Examples
assert_eq!(AckPolicy::for_peer_count(3).quorum, 2); // 2 of 3
assert_eq!(AckPolicy::for_peer_count(5).quorum, 3); // 3 of 5
assert_eq!(AckPolicy::for_peer_count(0).quorum, 1); // → anySourcepub fn all() -> Self
pub fn all() -> Self
“Every fanned-out peer must ack” policy with the default timeout.
Strictest consistency guarantee — the put is only considered durable once every target has confirmed. Useful for critical writes where partial replication is unacceptable.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Returns a new policy with the given timeout (other fields preserved).
Useful when callers want a faster-failing deadline than the Gun.js default, or a longer grace period for high-latency networks.
Sourcepub fn with_quorum(self, quorum: usize) -> Self
pub fn with_quorum(self, quorum: usize) -> Self
Returns a new policy with the given quorum requirement.
Clamped to >= 1 (a quorum of 0 would resolve immediately, which
is almost certainly not what the caller intends).
Trait Implementations§
impl Copy for AckPolicy
Source§impl Default for AckPolicy
impl Default for AckPolicy
Source§fn default() -> Self
fn default() -> Self
Defaults to AckPolicy::any — first ack wins, Gun.js compatible.
impl Eq for AckPolicy
impl StructuralPartialEq for AckPolicy
Auto Trait Implementations§
impl Freeze for AckPolicy
impl RefUnwindSafe for AckPolicy
impl Send for AckPolicy
impl Sync for AckPolicy
impl Unpin for AckPolicy
impl UnsafeUnpin for AckPolicy
impl UnwindSafe for AckPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.