Struct InterfaceBuilder

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

Builder, that used for creating Interfaces.

§Examples

use wireguard_conf::prelude::*;

let server_private_key = PrivateKey::random();

let interface = InterfaceBuilder::new()
    .address("10.0.0.1/24".parse().unwrap())
    .listen_port(6969)
    .private_key(server_private_key.clone())
    .set_dns(vec!["8.8.8.8".to_string(), "8.8.4.4".to_string()])
    .endpoint("vpn.example.com".to_string())
    // .add_peer(some_peer)
    .build();

assert_eq!(interface.address, "10.0.0.1/24".parse().unwrap());
assert_eq!(interface.listen_port, Some(6969));
assert_eq!(interface.private_key, server_private_key);
assert_eq!(interface.dns, vec!["8.8.8.8", "8.8.4.4"]);
assert_eq!(interface.endpoint, Some("vpn.example.com".to_string()));

Implementations§

Source§

impl InterfaceBuilder

Source

pub fn new() -> InterfaceBuilder

Source

pub fn address(self, address: Ipv4Net) -> Self

Set the address.

Wireguard Docs

Source

pub fn listen_port(self, listen_port: u16) -> Self

Set the listen port.

Wireguard Docs

Source

pub fn private_key(self, private_key: PrivateKey) -> Self

Set the private key.

Wireguard Docs

Source

pub fn set_dns(self, dns: Vec<String>) -> Self

Set the DNS servers array.

Wireguard Docs

Source

pub fn add_dns(self, dns: String) -> Self

Add DNS server.

Wireguard Docs

Source

pub fn endpoint(self, endpoint: String) -> Self

Set the endpoint.

§Note
  • In interface’s config this set # Name = ...
  • If you export interface via [Interface::as_peer()], exported peer will have this Peer.endpoint

Wireguard Docs

Source

pub fn set_peers(self, peers: Vec<Peer>) -> Self

Set the Peers array.

Wireguard Docs

Source

pub fn add_peer(self, peer: Peer) -> Self

Add peer.

Wireguard Docs

Source

pub fn amnezia_settings(self, amnezia_settings: AmneziaSettings) -> Self

Available on crate feature amneziawg only.

Sets AmneziaWG obfuscation values.

AmneziaWG Docs

Source

pub fn build(self) -> Interface

Creates Interface.

Trait Implementations§

Source§

impl Default for InterfaceBuilder

Source§

fn default() -> InterfaceBuilder

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

Auto Trait Implementations§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
Source§

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

Source§

fn vzip(self) -> V