Struct Protocols

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

A set of supported or required subprotocol versions.

This type supports both recognized subprotocols (listed in ProtoKind), and unrecognized subprotocols (stored by name).

To construct an instance, use the FromStr trait:

use tor_protover::Protocols;
let p: Result<Protocols,_> = "Link=1-3 LinkAuth=2-3 Relay=1-2".parse();

Implementations§

Source§

impl Protocols

Source

pub fn new() -> Self

Return a new empty set of protocol versions.

Source

pub fn is_empty(&self) -> bool

Return true if this list of protocols is empty.

Source

pub fn supports_known_subver(&self, proto: ProtoKind, ver: u8) -> bool

Check whether a known protocol version is supported.

use tor_protover::*;
let protos: Protocols = "Link=1-3 HSDir=2,4-5".parse().unwrap();

assert!(protos.supports_known_subver(ProtoKind::Link, 2));
assert!(protos.supports_known_subver(ProtoKind::HSDir, 4));
assert!(! protos.supports_known_subver(ProtoKind::HSDir, 3));
assert!(! protos.supports_known_subver(ProtoKind::LinkAuth, 3));
Source

pub fn supports_subver(&self, proto: &str, ver: u8) -> bool

Check whether a protocol version identified by a string is supported.

use tor_protover::*;
let protos: Protocols = "Link=1-3 Foobar=7".parse().unwrap();

assert!(protos.supports_subver("Link", 2));
assert!(protos.supports_subver("Foobar", 7));
assert!(! protos.supports_subver("Link", 5));
assert!(! protos.supports_subver("Foobar", 6));
assert!(! protos.supports_subver("Wombat", 3));
Source

pub fn supports_named_subver(&self, protover: NamedSubver) -> bool

Check whether a protocol version is supported.

use tor_protover::*;
let protos: Protocols = "Link=1-5 Desc=2-4".parse().unwrap();
assert!(protos.supports_named_subver(named::DESC_FAMILY_IDS)); // Desc=4
assert!(! protos.supports_named_subver(named::CONFLUX_BASE)); // Conflux=1
Source

pub fn supports_numbered_subver(&self, protover: NumberedSubver) -> bool

Check whether a numbered subprotocol capability is supported.

use tor_protover::*;
let protos: Protocols = "Link=1-5 Desc=2-4".parse().unwrap();
assert!(protos.supports_numbered_subver(NumberedSubver::new(ProtoKind::Desc, 4)));
assert!(! protos.supports_numbered_subver(NumberedSubver::new(ProtoKind::Conflux, 1)));
Source

pub fn difference(&self, other: &Protocols) -> Protocols

Return a Protocols holding every protocol flag that is present in self but not other.

use tor_protover::*;
let protos: Protocols = "Desc=2-4 Microdesc=1-5".parse().unwrap();
let protos2: Protocols = "Desc=3 Microdesc=3".parse().unwrap();
assert_eq!(protos.difference(&protos2),
           "Desc=2,4 Microdesc=1-2,4-5".parse().unwrap());
Source

pub fn union(&self, other: &Protocols) -> Protocols

Return a Protocols holding every protocol flag that is present in self or other or both.

use tor_protover::*;
let protos: Protocols = "Desc=2-4 Microdesc=1-5".parse().unwrap();
let protos2: Protocols = "Desc=3 Microdesc=10".parse().unwrap();
assert_eq!(protos.union(&protos2),
           "Desc=2-4 Microdesc=1-5,10".parse().unwrap());
Source

pub fn intersection(&self, other: &Protocols) -> Protocols

Return a Protocols holding every protocol flag that is present in both self and other.

use tor_protover::*;
let protos: Protocols = "Desc=2-4 Microdesc=1-5".parse().unwrap();
let protos2: Protocols = "Desc=3 Microdesc=10".parse().unwrap();
assert_eq!(protos.intersection(&protos2),
           "Desc=3".parse().unwrap());

Trait Implementations§

Source§

impl Clone for Protocols

Source§

fn clone(&self) -> Protocols

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Protocols

Source§

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

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

impl Default for Protocols

Source§

fn default() -> Protocols

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

impl<'de> Deserialize<'de> for Protocols
where Self: FromStr, <Self as FromStr>::Err: Display,

Source§

fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Protocols

The Display trait formats a protocol set in the format expected by Tor consensus documents.

use tor_protover::*;
let protos: Protocols = "Link=1,2,3 Foobar=7 Relay=2".parse().unwrap();
assert_eq!(format!("{}", protos),
           "Foobar=7 Link=1-3 Relay=2");
Source§

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

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

impl FromIterator<NamedSubver> for Protocols

Source§

fn from_iter<T: IntoIterator<Item = NamedSubver>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for Protocols

A Protocols set can be parsed from a string according to the format used in Tor consensus documents.

A protocols set is represented by a space-separated list of entries. Each entry is of the form Name=Versions, where Name is the name of a protocol, and Versions is a comma-separated list of version numbers and version ranges. Each version range is a pair of integers separated by -.

No protocol name may be listed twice. No version may be listed twice for a single protocol. All versions must be in range 0 through 63 inclusive.

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, ParseError>

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

impl Hash for Protocols

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl PartialEq for Protocols

Source§

fn eq(&self, other: &Protocols) -> 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.
Source§

impl Serialize for Protocols
where Self: Display,

Source§

fn serialize<__S>(&self, serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Protocols

Source§

impl StructuralPartialEq for Protocols

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T