pub struct PeerBuilder { /* private fields */ }Expand description
Builder, that used for creating Peers.
§Examples
use wireguard_conf::prelude::*;
use either::Either;
let client_private_key = PrivateKey::random();
let peer = PeerBuilder::new()
.endpoint("public.client.example.com".to_string())
.add_allowed_ip("10.0.0.2/32".parse().unwrap())
.private_key(client_private_key.clone())
// if you don't want to generate interface from peer, you can provide public key
// instead of private_key:
// .public_key(client_public_key)
.build();
assert_eq!(peer.endpoint, Some("public.client.example.com".to_string()));
assert_eq!(peer.allowed_ips, vec!["10.0.0.2/32".parse().unwrap()]);
assert_eq!(peer.key, Either::Left(client_private_key));Implementations§
Source§impl PeerBuilder
impl PeerBuilder
pub fn new() -> PeerBuilder
Sourcepub fn endpoint(self, endpoint: String) -> PeerBuilder
pub fn endpoint(self, endpoint: String) -> PeerBuilder
Sets endpoint.
Sourcepub fn set_allowed_ips(self, ip: Vec<Ipv4Net>) -> PeerBuilder
pub fn set_allowed_ips(self, ip: Vec<Ipv4Net>) -> PeerBuilder
Sets Allowed IPs array.
Sourcepub fn add_allowed_ip(self, ip: Ipv4Net) -> PeerBuilder
pub fn add_allowed_ip(self, ip: Ipv4Net) -> PeerBuilder
Adds allowed IP.
Sourcepub fn private_key(self, private_key: PrivateKey) -> PeerBuilder
pub fn private_key(self, private_key: PrivateKey) -> PeerBuilder
Sourcepub fn public_key(self, public_key: PublicKey) -> PeerBuilder
pub fn public_key(self, public_key: PublicKey) -> PeerBuilder
Sets public key.
Sourcepub fn amnezia_settings(self, amnezia_settings: AmneziaSettings) -> Self
Available on crate feature amneziawg only.
pub fn amnezia_settings(self, amnezia_settings: AmneziaSettings) -> Self
amneziawg only.Sets AmneziaWG obfuscation values.
Trait Implementations§
Source§impl Default for PeerBuilder
impl Default for PeerBuilder
Source§fn default() -> PeerBuilder
fn default() -> PeerBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PeerBuilder
impl RefUnwindSafe for PeerBuilder
impl Send for PeerBuilder
impl Sync for PeerBuilder
impl Unpin for PeerBuilder
impl UnwindSafe for PeerBuilder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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