Struct mz_ore::id_gen::PortAllocator
source · [−]pub struct PortAllocator(_);
Expand description
Manages allocation of process ports. Similar to IdAllocator
but specific to
the allocation of ports.
Note that the current implementation is fairly memory inefficient.
Implementations
sourceimpl PortAllocator
impl PortAllocator
sourcepub fn new(min: u16, max: u16) -> PortAllocator
pub fn new(min: u16, max: u16) -> PortAllocator
Creates a new PortAllocator
that will assign ports between min
and
max
, both inclusive.
sourcepub fn new_with_filter(min: u16, max: u16, banned: &[u16]) -> PortAllocator
pub fn new_with_filter(min: u16, max: u16, banned: &[u16]) -> PortAllocator
Creates a new PortAllocator
that will assign ports between min
and
max
, both inclusive.
The ports listed in banned
will not be assigned.
sourcepub fn alloc(&self) -> Option<u16>
pub fn alloc(&self) -> Option<u16>
Allocates a new port.
Returns None
if the allocator is exhausted.
sourcepub fn free(&self, id: u16)
pub fn free(&self, id: u16)
Releases a new port back to the pool.
It is undefined behavior to free an port twice, or to free an port that was not allocated by this allocator.
sourcepub fn mark_allocated(&self, port: u16) -> bool
pub fn mark_allocated(&self, port: u16) -> bool
Marks a port as already allocated.
Returns false if port was previously allocated and true otherwise.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for PortAllocator
impl Send for PortAllocator
impl Sync for PortAllocator
impl Unpin for PortAllocator
impl UnwindSafe for PortAllocator
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request