Struct Ports

Source
pub struct Ports { /* private fields */ }
Expand description

port table.

Implementations§

Source§

impl Ports

Source

pub fn new() -> Self

Source

pub fn capacity(&self) -> usize

get ports capacity.

§Examples
use turn_rs::router::ports::*;

let ports = Ports::new();
assert_eq!(ports.capacity(), 65535 - 49152);
Source

pub fn len(&self) -> usize

get ports allocated size.

§Examples
use turn_rs::router::ports::*;

let ports = Ports::new();
assert_eq!(ports.len(), 0);
Source

pub fn is_empty(&self) -> bool

get ports allocated size is empty.

§Examples
use turn_rs::router::ports::*;

let ports = Ports::new();
assert_eq!(ports.is_empty(), true);
Source

pub fn get(&self, p: u16) -> Option<SocketAddr>

get address from port.

§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;

let ports = Ports::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let port = ports.alloc(&addr).unwrap();

assert!(ports.get(port).is_some());
Source

pub fn get_bound(&self, a: &SocketAddr, p: &SocketAddr) -> Option<u16>

get address bound port.

§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;

let local = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let peer = "127.0.0.1:8081".parse::<SocketAddr>().unwrap();

let pools = Ports::new();

let port = pools.alloc(&local).unwrap();
assert!(pools.bound(&local, port).is_some());
assert!(pools.bound(&peer, port).is_some());

assert_eq!(pools.get_bound(&local, &peer), Some(port));
Source

pub fn alloc(&self, a: &SocketAddr) -> Option<u16>

allocate port in ports.

§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;

let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();

let pools = Ports::new();
assert_eq!(pools.alloc(&addr).is_some(), true);
Source

pub fn bound(&self, addr: &SocketAddr, port: u16) -> Option<()>

bound address and peer port.

§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;

let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();

let pools = Ports::new();
let port = pools.alloc(&addr).unwrap();

assert!(pools.bound(&addr, port).is_some());
Source

pub fn remove(&self, a: &SocketAddr, ports: &[u16]) -> Option<()>

bound address and peer port.

§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;

let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();

let pools = Ports::new();
let port = pools.alloc(&addr).unwrap();

assert!(pools.bound(&addr, port).is_some());
assert!(pools.remove(&addr, &vec![port]).is_some());

Trait Implementations§

Source§

impl Default for Ports

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Ports

§

impl RefUnwindSafe for Ports

§

impl Send for Ports

§

impl Sync for Ports

§

impl Unpin for Ports

§

impl UnwindSafe for Ports

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V