Struct bip32::Prefix

source ·
#[non_exhaustive]
pub struct Prefix { /* private fields */ }
Expand description

BIP32 extended key prefixes a.k.a. “versions” (e.g. xpub, xprv)

The BIP32 spec describes these as “versions” and gives examples for xprv/xpub (mainnet) and tprv/tpub (testnet), however in practice there are many more used (e.g. ypub, zpub).

Implementations§

source§

impl Prefix

source

pub const LENGTH: usize = 4usize

Length of a prefix in ASCII characters.

source

pub const TPRV: Self = _

tprv prefix

source

pub const TPUB: Self = _

tpub prefix

source

pub const XPRV: Self = _

xprv prefix

source

pub const XPUB: Self = _

xpub prefix

source

pub const YPRV: Self = _

yprv prefix

source

pub const YPUB: Self = _

ypub prefix

source

pub const ZPRV: Self = _

zprv prefix

source

pub const ZPUB: Self = _

zpub prefix

source

pub const fn from_parts_unchecked(s: &str, version: Version) -> Self

Create a new prefix from the given 4-character string and version number. The main intended use case for this function is Prefix constants such as Prefix::XPRV.

Warning

Use this function with care: No consistency check is performed! It is up to the caller to ensure that the version number matches the prefix.

Panics

Panics if s is not 4 chars long, or any of the chars lie outside of the supported range: lower case (a..=z) or upper case (A..=Z) letters.

source

pub fn from_bytes(bytes: [u8; 4]) -> Result<Self>

Create a new prefix from the given encoded bytes.

These bytes represent the big endian serialization of a Version integer.

source

pub fn as_str(&self) -> &str

Get the prefix as a string.

source

pub fn is_public(self) -> bool

Is this a public key?

source

pub fn is_private(self) -> bool

Is this a private key?

source

pub fn version(self) -> Version

Get the Version number.

source

pub fn to_bytes(self) -> [u8; 4]

Serialize the Version number as big-endian bytes.

Trait Implementations§

source§

impl AsRef<str> for Prefix

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Prefix

source§

fn clone(&self) -> Prefix

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 Prefix

source§

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

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

impl Display for Prefix

source§

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

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

impl From<&Prefix> for Version

source§

fn from(prefix: &Prefix) -> Version

Converts to this type from the input type.
source§

impl From<Prefix> for Version

source§

fn from(prefix: Prefix) -> Version

Converts to this type from the input type.
source§

impl Ord for Prefix

source§

fn cmp(&self, other: &Prefix) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Prefix> for Prefix

source§

fn eq(&self, other: &Prefix) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Prefix> for Prefix

source§

fn partial_cmp(&self, other: &Prefix) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<&[u8]> for Prefix

§

type Error = Error

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

fn try_from(bytes: &[u8]) -> Result<Prefix>

Performs the conversion.
source§

impl TryFrom<u32> for Prefix

§

type Error = Error

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

fn try_from(version: Version) -> Result<Self>

Performs the conversion.
source§

impl Copy for Prefix

source§

impl Eq for Prefix

source§

impl StructuralEq for Prefix

source§

impl StructuralPartialEq for Prefix

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.