Struct tor_linkspec::ByRelayIds

source ·
pub struct ByRelayIds<H: HasRelayIds>{ /* private fields */ }
Expand description

A set of objects that can be accessed by relay identity.

No more than one object in the set can have any given relay identity.

§Invariants

Every object in the set MUST have at least one recognized relay identity; if it does not, it cannot be inserted.

This set may panic or give incorrect results if the values can change their keys through interior mutability.

A set of elements of type H whose members can be accessed by multiple keys.

The keys are: * rsa (RsaIdentity) (Option) * ed25519 (Ed25519Identity) (Option)Each member has a value for each required key, and up to one value for each optional key. The set contains at most one member for any value of a given key.

§Requirements

Key types must have consistent Hash and Eq implementations, as they will be used as keys in a HashMap.

If all keys are optional, then every element in this set must have at least one non-None key.

An element must not change its keys over time through interior mutability.

⚠️ If any of these rules is violated, the consequences are unspecified, and could include panics or wrong answers (but not memory-unsafety).

§Limitations

This could be more efficient in space and time.

Implementations§

source§

impl<H: HasRelayIds> ByRelayIds<H>

source

pub fn new() -> Self

Construct a new ByRelayIds

source

pub fn with_capacity(n: usize) -> Self

Construct a new ByRelayIds with a given capacity.

source

pub fn by_rsa<BorrowAsKey_>(&self, key: &BorrowAsKey_) -> Option<&H>
where RsaIdentity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Return a reference to the element whose rsa is key.

Return None if there is no such element.

source

pub unsafe fn by_rsa_mut<BorrowAsKey_>( &mut self, key: &BorrowAsKey_ ) -> Option<&mut H>
where RsaIdentity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Return a mutable reference to the element whose rsa is key.

Return None if there is no such element.

§Safety

This function can put this set into an inconsistent state if the mutable reference is used to change any of the keys. Doing this does not risk Rust safety violations (such as undefined behavior), but it may nonetheless make your program incorrect by causing other functions on this object to panic or give incorrect results.

If you cannot prove to yourself that this won’t happen, then you should use modify_by_* instead.

source

pub fn contains_rsa<BorrowAsKey_>(&mut self, rsa: &BorrowAsKey_) -> bool
where RsaIdentity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Return true if this set contains an element whose rsa is key.

source

pub fn remove_by_rsa<BorrowAsKey_>(&mut self, rsa: &BorrowAsKey_) -> Option<H>
where RsaIdentity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Remove the element whose rsa is key

Return that element on success, and None if there is no such element.“)] rsa

source

pub fn modify_by_rsa<BorrowAsKey_, F_>( &mut self, rsa: &BorrowAsKey_, func: F_ ) -> Vec<H>
where RsaIdentity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized, F_: FnOnce(&mut H),

Modify the element with the given value for rsa by applying func` to it.

func is allowed to change the keys for this value. All indices are updated to refer to the new keys. If the new keys conflict with any previous values, those values are replaced and returned in a vector.

If func causes the value to have no keys at all, then the value itself is also removed and returned in the result vector.

Note that because this function needs to copy all key values and check whether they have changed, it is not terribly efficient.

source

pub fn by_ed25519<BorrowAsKey_>(&self, key: &BorrowAsKey_) -> Option<&H>
where Ed25519Identity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Return a reference to the element whose ed25519 is key.

Return None if there is no such element.

source

pub unsafe fn by_ed25519_mut<BorrowAsKey_>( &mut self, key: &BorrowAsKey_ ) -> Option<&mut H>
where Ed25519Identity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Return a mutable reference to the element whose ed25519 is key.

Return None if there is no such element.

§Safety

This function can put this set into an inconsistent state if the mutable reference is used to change any of the keys. Doing this does not risk Rust safety violations (such as undefined behavior), but it may nonetheless make your program incorrect by causing other functions on this object to panic or give incorrect results.

If you cannot prove to yourself that this won’t happen, then you should use modify_by_* instead.

source

pub fn contains_ed25519<BorrowAsKey_>(&mut self, ed25519: &BorrowAsKey_) -> bool
where Ed25519Identity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Return true if this set contains an element whose ed25519 is key.

source

pub fn remove_by_ed25519<BorrowAsKey_>( &mut self, ed25519: &BorrowAsKey_ ) -> Option<H>
where Ed25519Identity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized,

Remove the element whose ed25519 is key

Return that element on success, and None if there is no such element.“)] ed25519

source

pub fn modify_by_ed25519<BorrowAsKey_, F_>( &mut self, ed25519: &BorrowAsKey_, func: F_ ) -> Vec<H>
where Ed25519Identity: Borrow<BorrowAsKey_>, BorrowAsKey_: Hash + Eq + ?Sized, F_: FnOnce(&mut H),

Modify the element with the given value for ed25519 by applying func` to it.

func is allowed to change the keys for this value. All indices are updated to refer to the new keys. If the new keys conflict with any previous values, those values are replaced and returned in a vector.

If func causes the value to have no keys at all, then the value itself is also removed and returned in the result vector.

Note that because this function needs to copy all key values and check whether they have changed, it is not terribly efficient.

source

pub fn values(&self) -> impl Iterator<Item = &H> + '_

Return an iterator over the elements in this container.

source

pub fn into_values(self) -> impl Iterator<Item = H>

Consumer this container and return an iterator of its values.

source

pub fn try_insert(&mut self, value: H) -> Result<Vec<H>, Error>

Try to insert the value value.

Remove any previous values that shared any keys with value, and return them in a vector on success.

Return Err(Error::NoKeys) if all the keys are optional, and value has no keys at all.

source

pub fn insert(&mut self, value: H) -> Vec<H>

Try to insert the value value.

Remove any previous values that shared any keys with value, and return them in a vector.

§Panics

Panics if all the keys are optional, and value has no keys at all.

source

pub fn len(&self) -> usize

Return the number of elements in this container.

source

pub fn is_empty(&self) -> bool

Return true if there are no elements in this container.

source

pub fn capacity(&self) -> usize

Return the number of elements for which this container has allocated storage.

source

pub fn retain<F>(&mut self, pred: F)
where F: FnMut(&H) -> bool,

Remove every element that does not satisfy the predicate pred.

source

pub fn check_invariants(&self)

Assert that this set appears to be in an internally consistent state.

This method can be somewhat expensive, and it should never fail unless your code has a bug.

§Panics

Panics if it finds bugs in this object, or constraint violations in its elements. See the (type documentation)Self for a list of constraints.

source§

impl<H: HasRelayIds> ByRelayIds<H>

source

pub fn by_id<'a, T>(&self, key: T) -> Option<&H>
where T: Into<RelayIdRef<'a>>,

Return the value in this set (if any) that has the key key.

source

pub fn remove_by_id<'a, T>(&mut self, key: T) -> Option<H>
where T: Into<RelayIdRef<'a>>,

Return the value in this set (if any) that has the key key.

source

pub fn modify_by_id<'a, T, F>(&mut self, key: T, func: F) -> Vec<H>
where T: Into<RelayIdRef<'a>>, F: FnOnce(&mut H),

Modify the value in this set (if any) that has the key key.

Return values are as for modify_by_ed25519

source

pub fn by_all_ids<T>(&self, key: &T) -> Option<&H>
where T: HasRelayIds,

Return the value in this set (if any) that has all the relay IDs that key does.

Return None if key has no relay IDs.

source

pub fn modify_by_all_ids<T, F>(&mut self, key: &T, func: F) -> Vec<H>
where T: HasRelayIds, F: FnOnce(&mut H),

Modify the value in this set (if any) that has all the relay IDs that key does.

Return values are as for modify_by_ed25519

source

pub fn remove_exact<T>(&mut self, key: &T) -> Option<H>
where T: HasRelayIds,

Remove the single value in this set (if any) that has exactly the same relay IDs that key does

source

pub fn remove_by_all_ids<T>(&mut self, key: &T) -> Option<H>
where T: HasRelayIds,

Remove the single value in this set (if any) that has all the same relay IDs that key does.

source

pub fn all_overlapping<T>(&self, key: &T) -> Vec<&H>
where T: HasRelayIds,

Return a reference to every element in this set that shares any ID with key.

No element is returned more than once.

Trait Implementations§

source§

impl<H: Clone + HasRelayIds> Clone for ByRelayIds<H>

source§

fn clone(&self) -> ByRelayIds<H>

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<H: Debug + HasRelayIds> Debug for ByRelayIds<H>

source§

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

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

impl<H: HasRelayIds> Default for ByRelayIds<H>

source§

fn default() -> Self

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

impl<H: HasRelayIds> FromIterator<H> for ByRelayIds<H>

source§

fn from_iter<IntoIter_>(iter: IntoIter_) -> Self
where IntoIter_: IntoIterator<Item = H>,

Creates a value from an iterator. 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> Instrument for T

source§

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

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

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

§

type Output = T

Should always be Self
source§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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