Struct safe_app::XorName [−][src]
A XOR_NAME_BITS
-bit number, viewed as a point in XOR space.
This wraps an array of XOR_NAME_LEN
bytes, i. e. a number
between 0 and 2XOR_NAME_BITS
- 1.
XOR space is the space of these numbers, with the XOR metric as a notion of distance,
i. e. the points with IDs x
and y
are considered to have distance x xor y
.
Methods
impl XorName
[src]
impl XorName
pub fn to_hex(&self) -> String
[src]
pub fn to_hex(&self) -> String
Hex-encode the XorName
as a String
.
pub fn count_differing_bits(&self, other: &XorName) -> u32
[src]
pub fn count_differing_bits(&self, other: &XorName) -> u32
Returns the number of bits in which self
differs from other
.
pub fn from_hex(s: &str) -> Result<XorName, XorNameFromHexError>
[src]
pub fn from_hex(s: &str) -> Result<XorName, XorNameFromHexError>
Hex-decode a XorName
from a &str
.
pub fn closer(&self, lhs: &XorName, rhs: &XorName) -> bool
[src]
pub fn closer(&self, lhs: &XorName, rhs: &XorName) -> bool
Returns true if lhs
is closer to self
than rhs
.
Equivalently, this returns true
if in the most significant bit where lhs
and rhs
disagree, lhs
agrees with self
.
pub fn closer_or_equal(&self, lhs: &XorName, rhs: &XorName) -> bool
[src]
pub fn closer_or_equal(&self, lhs: &XorName, rhs: &XorName) -> bool
Returns true if lhs
is closer to self
than rhs
, or lhs == rhs
.
Trait Implementations
impl Rand for XorName
[src]
impl Rand for XorName
fn rand<R>(rng: &mut R) -> XorName where
R: Rng,
[src]
fn rand<R>(rng: &mut R) -> XorName where
R: Rng,
Generates a random instance of this type using the specified source of randomness. Read more
impl Xorable for XorName
[src]
impl Xorable for XorName
fn common_prefix(&self, other: &XorName) -> usize
[src]
fn common_prefix(&self, other: &XorName) -> usize
Returns the length of the common prefix with the other
name; e. g. the when other = 11110000
and self = 11111111
this is 4. Read more
fn cmp_distance(&self, lhs: &XorName, rhs: &XorName) -> Ordering
[src]
fn cmp_distance(&self, lhs: &XorName, rhs: &XorName) -> Ordering
Compares the distance of the arguments to self
. Returns Less
if lhs
is closer, Greater
if rhs
is closer, and Equal
if lhs == rhs
. (The XOR distance can only be equal if the arguments are equal.) Read more
fn bit(&self, i: usize) -> bool
[src]
fn bit(&self, i: usize) -> bool
Returns true
if the i
-th bit is 1
.
fn differs_in_bit(&self, name: &XorName, i: usize) -> bool
[src]
fn differs_in_bit(&self, name: &XorName, i: usize) -> bool
Returns true
if the i
-th bit of other has a different value to the i
-th bit of self
.
fn with_flipped_bit(self, i: usize) -> XorName
[src]
fn with_flipped_bit(self, i: usize) -> XorName
Returns a copy of self
, with the index
-th bit flipped. Read more
fn with_bit(self, i: usize, bit: bool) -> XorName
[src]
fn with_bit(self, i: usize, bit: bool) -> XorName
Returns a copy of self
, with the index
-th bit set to bit
. Read more
fn binary(&self) -> String
[src]
fn binary(&self) -> String
Returns a binary format string, with leading zero bits included.
fn debug_binary(&self) -> String
[src]
fn debug_binary(&self) -> String
Returns a binary debug format string of ????????...????????
fn set_remaining(self, n: usize, val: bool) -> XorName
[src]
fn set_remaining(self, n: usize, val: bool) -> XorName
Returns a copy of self with first n
bits preserved, and remaining bits set to 0 (val == false) or 1 (val == true). Read more
fn from_hash<T>(hash: T) -> XorName where
T: AsRef<[u8]>,
[src]
fn from_hash<T>(hash: T) -> XorName where
T: AsRef<[u8]>,
Returns a Self
instance constructed from an array of bytes.
fn bit_len() -> usize
[src]
fn bit_len() -> usize
Returns the number of bits in Self
.
impl PartialOrd<XorName> for XorName
[src]
impl PartialOrd<XorName> for XorName
fn partial_cmp(&self, other: &XorName) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &XorName) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &XorName) -> bool
[src]
fn lt(&self, other: &XorName) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &XorName) -> bool
[src]
fn le(&self, other: &XorName) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &XorName) -> bool
[src]
fn gt(&self, other: &XorName) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &XorName) -> bool
[src]
fn ge(&self, other: &XorName) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Hash for XorName
[src]
impl Hash for XorName
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'a> Sub<&'a XorName> for &'a XorName
[src]
impl<'a> Sub<&'a XorName> for &'a XorName
type Output = XorName
The resulting type after applying the -
operator.
fn sub(self, rhs: &XorName) -> <&'a XorName as Sub<&'a XorName>>::Output
[src]
fn sub(self, rhs: &XorName) -> <&'a XorName as Sub<&'a XorName>>::Output
Performs the -
operation.
impl Sub<XorName> for XorName
[src]
impl Sub<XorName> for XorName
type Output = XorName
The resulting type after applying the -
operator.
fn sub(self, rhs: XorName) -> <XorName as Sub<XorName>>::Output
[src]
fn sub(self, rhs: XorName) -> <XorName as Sub<XorName>>::Output
Performs the -
operation.
impl Clone for XorName
[src]
impl Clone for XorName
fn clone(&self) -> XorName
[src]
fn clone(&self) -> XorName
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for XorName
[src]
impl Debug for XorName
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Ord for XorName
[src]
impl Ord for XorName
fn cmp(&self, other: &XorName) -> Ordering
[src]
fn cmp(&self, other: &XorName) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl Binary for XorName
[src]
impl Binary for XorName
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl Index<Range<usize>> for XorName
[src]
impl Index<Range<usize>> for XorName
type Output = [u8]
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &[u8]
[src]
fn index(&self, index: Range<usize>) -> &[u8]
Performs the indexing (container[index]
) operation.
impl Index<RangeFull> for XorName
[src]
impl Index<RangeFull> for XorName
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeFull) -> &[u8]
[src]
fn index(&self, index: RangeFull) -> &[u8]
Performs the indexing (container[index]
) operation.
impl Index<RangeFrom<usize>> for XorName
[src]
impl Index<RangeFrom<usize>> for XorName
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &[u8]
[src]
fn index(&self, index: RangeFrom<usize>) -> &[u8]
Performs the indexing (container[index]
) operation.
impl Index<RangeTo<usize>> for XorName
[src]
impl Index<RangeTo<usize>> for XorName
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &[u8]
[src]
fn index(&self, index: RangeTo<usize>) -> &[u8]
Performs the indexing (container[index]
) operation.
impl Display for XorName
[src]
impl Display for XorName
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<'de> Deserialize<'de> for XorName
[src]
impl<'de> Deserialize<'de> for XorName
fn deserialize<__D>(
__deserializer: __D
) -> Result<XorName, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(
__deserializer: __D
) -> Result<XorName, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Default for XorName
[src]
impl Default for XorName
impl Serialize for XorName
[src]
impl Serialize for XorName
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for XorName
[src]
impl Copy for XorName
impl Eq for XorName
[src]
impl Eq for XorName
impl PartialEq<XorName> for XorName
[src]
impl PartialEq<XorName> for XorName
fn eq(&self, other: &XorName) -> bool
[src]
fn eq(&self, other: &XorName) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &XorName) -> bool
[src]
fn ne(&self, other: &XorName) -> bool
This method tests for !=
.
impl Not for XorName
[src]
impl Not for XorName
type Output = XorName
The resulting type after applying the !
operator.
fn not(self) -> XorName
[src]
fn not(self) -> XorName
Performs the unary !
operation.
impl<'a> Div<&'a u32> for &'a XorName
[src]
impl<'a> Div<&'a u32> for &'a XorName
type Output = XorName
The resulting type after applying the /
operator.
fn div(self, rhs: &u32) -> <&'a XorName as Div<&'a u32>>::Output
[src]
fn div(self, rhs: &u32) -> <&'a XorName as Div<&'a u32>>::Output
Performs the /
operation.
impl Div<u32> for XorName
[src]
impl Div<u32> for XorName