pub struct AcceptorConnectionGate { /* private fields */ }Expand description
Utility to track the number of active connections.
§Example
use links_core::prelude::*;
use std::num::NonZeroUsize;
let tracker = AcceptorConnectionGate::new(NonZeroUsize::new(2).unwrap());
assert_eq!(tracker.get_max_count(), 2);
assert_eq!(tracker.get_cur_count(), 0);
assert!( matches!(tracker.increment(), Ok(()) ) );
assert_eq!(tracker.get_cur_count(), 1);
assert!( matches!(tracker.increment(), Ok(()) ) );
assert_eq!(tracker.get_cur_count(), 2);
assert!( matches!(tracker.increment(), Err(_) ) );
assert_eq!(tracker.get_cur_count(), 2);
let barrier = tracker.get_new_connection_barrier();
let barrier2 = barrier.clone();
drop(barrier);
assert_eq!(tracker.get_cur_count(), 1);
drop(barrier2);
assert_eq!(tracker.get_cur_count(), 1);Implementations§
Source§impl AcceptorConnectionGate
impl AcceptorConnectionGate
pub fn new(max_count: NonZero<usize>) -> AcceptorConnectionGate
pub fn get_max_count(&self) -> usize
pub fn get_cur_count(&self) -> usize
Sourcepub fn increment(&self) -> Result<(), Error>
pub fn increment(&self) -> Result<(), Error>
Increments the current connection count by 1 if max_count is not exceeded, otherwise returns an ErrorKind::OutOfMemory.
pub fn decrement(&self)
pub fn get_new_connection_barrier(&self) -> RemoveConnectionBarrierOnDrop
Trait Implementations§
Source§impl Clone for AcceptorConnectionGate
impl Clone for AcceptorConnectionGate
Source§fn clone(&self) -> AcceptorConnectionGate
fn clone(&self) -> AcceptorConnectionGate
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AcceptorConnectionGate
impl RefUnwindSafe for AcceptorConnectionGate
impl Send for AcceptorConnectionGate
impl Sync for AcceptorConnectionGate
impl Unpin for AcceptorConnectionGate
impl UnsafeUnpin for AcceptorConnectionGate
impl UnwindSafe for AcceptorConnectionGate
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
Mutably borrows from an owned value. Read more