Struct NetNs

Source
pub struct NetNs<E: Env = DefaultEnv> { /* private fields */ }
Expand description

A network namespace type.

It could be used to enter network namespace.

Implementations§

Source§

impl<E: Env> NetNs<E>

Source

pub fn new_with_env<S: AsRef<str>>(ns_name: S, env: E) -> Result<Self>

Creates a new NetNs with the specified name and Env.

The persist dir of network namespace will be created if it doesn’t already exist.

Source

pub fn path(&self) -> &Path

Gets the path of this network namespace.

Source

pub fn env(&self) -> Option<&E>

Gets the Env of this network namespace.

Source

pub fn file(&self) -> &File

Gets the Env of this network namespace.

Source

pub fn enter(&self) -> Result<()>

Makes the current thread enter this network namespace.

Requires elevated privileges.

Source

pub fn get_from_env<S: AsRef<str>>(ns_name: S, env: E) -> Result<Self>

Returns the NetNs with the specified name and Env.

Source

pub fn remove(self) -> Result<()>

Removes this network namespace manually.

Once called, this instance will not be available.

Source

pub fn run<F, T>(&self, f: F) -> Result<T>
where F: FnOnce(&Self) -> T,

Run a closure in NetNs, which is specified by name and Env.

Requires elevated privileges.

Source§

impl NetNs

Source

pub fn new<S: AsRef<str>>(ns_name: S) -> Result<Self>

Creates a new persistent (bind-mounted) network namespace and returns an object representing that namespace, without switching to it.

The persist directory of network namespace will be created if it doesn’t already exist. This function will use DefaultEnv to create persist directory.

Requires elevated privileges.

Source

pub fn get<S: AsRef<str>>(ns_name: S) -> Result<Self>

Returns the NetNs with the specified name and DefaultEnv.

Source

pub fn run_in<S, F, T>(ns_name: S, f: F) -> Result<T>
where S: AsRef<str>, F: FnOnce(&Self) -> T,

Run a closure in NetNs, which is specified by name and DefaultEnv.

Requires elevated privileges.

Trait Implementations§

Source§

impl<E: Debug + Env> Debug for NetNs<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Env> Display for NetNs<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E1: Env, E2: Env> PartialEq<NetNs<E1>> for NetNs<E2>

Source§

fn eq(&self, other: &NetNs<E1>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<E> Freeze for NetNs<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for NetNs<E>
where E: RefUnwindSafe,

§

impl<E> Send for NetNs<E>
where E: Send,

§

impl<E> Sync for NetNs<E>
where E: Sync,

§

impl<E> Unpin for NetNs<E>
where E: Unpin,

§

impl<E> UnwindSafe for NetNs<E>
where E: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.