Skip to main content

RuleBuilder

Struct RuleBuilder 

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

A builder struct for Rules. This should generally be constructed with Rule::builder, or a shortcut such as Rule::source_cidr.

Implementations§

Source§

impl RuleBuilder

Source

pub fn action(self, action: Action) -> Self

Sets the rule’s Action

The action applies to all packets matching the rule, unless overridden by successive rules.

Source

pub fn protocol(self, protocol: Protocol) -> Self

Sets the rule’s Protocol

Source

pub fn source_cidr(self, cidr_range: impl IntoIpNet) -> Self

Sets the source CIDR.

Accepts any IP address or CIDR notation:

  • "127.0.0.1": matches a single IP
  • "10.0.0.0/24": matches a CIDR

This additionally accepts std::net::IpAddr, std::net::Ipv4Addr, std::net::Ipv6Addr, ipnet::IpNet, ipnet::Ipv4Net, and ipnet::Ipv6Net.

Source

pub fn source_port(self, port: impl IntoPortRange) -> Self

Sets the source port

Accepts a u16 or range

Source

pub fn destination_cidr(self, cidr_range: impl IntoIpNet) -> Self

Sets the destination CIDR.

Accepts any IP address or CIDR notation:

  • "127.0.0.1": matches a single IP
  • "10.0.0.0/24": matches a CIDR

This additionally accepts std::net::IpAddr, std::net::Ipv4Addr, std::net::Ipv6Addr, ipnet::IpNet, ipnet::Ipv4Net, and ipnet::Ipv6Net.

Source

pub fn destination_port(self, port: impl IntoPortRange) -> Self

Sets the destination port

Accepts a u16 or range

Source

pub fn build(self) -> Result<Rule, RuleError>

Builds the Rule.

§Errors

Returns an RuleError if there is a missing action, invalid cidr, or no constraints (ips, ports, protocols).

Trait Implementations§

Source§

impl Default for RuleBuilder

Source§

fn default() -> RuleBuilder

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

impl TryFrom<RuleBuilder> for Rule

Source§

type Error = RuleError

The type returned in the event of a conversion error.
Source§

fn try_from(value: RuleBuilder) -> Result<Self, Self::Error>

Performs the conversion.

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, 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.