pub struct PortPolicy { /* private fields */ }
Expand description

A policy to match zero or more TCP/UDP ports.

These are used in Tor to summarize all policies in microdescriptors, and Ipv6 policies in router descriptors.

NOTE: If a port is listed as accepted, it doesn’t mean that the relay allows every address on that port. Instead, a port is listed if a relay will exit to most public addresses on that port. Therefore, unlike super::addrpolicy::AddrPolicy objects, these policies cannot tell you if a port is definitely allowed or rejected: only if it is probably allowed or rejected.

Examples

use tor_netdoc::types::policy::PortPolicy;
let policy: PortPolicy = "accept 1-1023,8000-8999,60000-65535".parse().unwrap();

assert!(policy.allows_port(22));
assert!(policy.allows_port(8000));
assert!(! policy.allows_port(1024));
assert!(! policy.allows_port(9000));

Implementations

Return a new PortPolicy that rejects all ports.

Return true iff port is allowed by this policy.

Replace this PortPolicy with an interned copy, to save memory.

Return true if this policy allows any ports at all.

Example
use tor_netdoc::types::policy::PortPolicy;

let policy: PortPolicy = "accept 22".parse().unwrap();
assert!(policy.allows_some_port());
let policy2: PortPolicy = "reject 1-65535".parse().unwrap();
assert!(! policy2.allows_some_port());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.