### Handling File Metadata with `and_then` Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/hash/type.Result.html?search=u32+-%3E+bool Shows how to use `and_then` to chain fallible operations when working with file system metadata, such as getting the modification time. This example highlights handling potential errors like file not found. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Result transpose() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates transposing a Result of an Option into an Option of a Result. Ok(None) maps to None. ```rust struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### Start Struct/Array Encoding Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/abor/struct.Encoder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Marks the beginning of a struct or array encoding. Note: Arrays cannot contain more than 256 elements. ```rust pub fn struct_start(self) -> Self ``` -------------------------------- ### Result is_ok() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Checks if the Result is the Ok variant. Returns true if it is Ok, false otherwise. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### Result copied() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates mapping a Result<&T, E> to a Result by copying the Ok value. Requires T to implement the Copy trait. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Result flatten() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates converting a Result, E> into a Result. This removes one level of nesting. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` -------------------------------- ### Result is_ok_and() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Checks if the Result is Ok and its value satisfies a given predicate. Returns false if the Result is Err. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Using expect for environment variable retrieval Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates a recommended use case for `expect` where a specific environment variable is expected to be set. The message clearly states the expectation and the reason for it. ```Rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### Result cloned() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates mapping a Result<&T, E> to a Result by cloning the Ok value. Requires T to implement the Clone trait. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Result copied() Method for &mut T Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates mapping a Result<&mut T, E> to a Result by copying the Ok value. Requires T to implement the Copy trait. ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### CloneToUninit Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html This is a nightly-only experimental API for performing copy-assignment from self to a mutable byte pointer destination. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn clone_to_uninit` ### Parameters - `dest` (*mut u8) - A mutable pointer to the destination memory location. ``` -------------------------------- ### type_id Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/hash/struct.Blake2b224.html Gets the `TypeId` of `self`. ```APIDOC ## type_id ### Description Gets the `TypeId` of `self`. ### Method (Implicitly called via trait) ### Parameters None ### Response - **TypeId**: The `TypeId` of the object. ``` -------------------------------- ### Pub::from_xpub Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/algorithms/ed25519/struct.Pub.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a new Pub key from an existing XPub. This is the primary way to create a public key instance from extended public key data. ```APIDOC ## Pub::from_xpub ### Description Creates a `Pub` key from an `XPub`. ### Method `Pub::from_xpub(xpub: &XPub) -> Self` ### Parameters - **xpub** (`&XPub`): A reference to the extended public key from which to derive the public key. ``` -------------------------------- ### Bip32PublicKey::type_id Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html?search=std%3A%3Avec Gets the TypeId of the Bip32PublicKey. ```APIDOC ## Bip32PublicKey::type_id ### Description Gets the `TypeId` of the `Bip32PublicKey`. ### Method `type_id(&self) -> TypeId` ``` -------------------------------- ### Get PublicKey Hash Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.PublicKey.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Computes the Ed25519KeyHash for the PublicKey. ```rust pub fn hash(&self) -> Ed25519KeyHash ``` -------------------------------- ### Rust Result unwrap() - Ok Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates the basic usage of `unwrap()` on a `Result` when it holds an `Ok` value. This method returns the contained `Ok` value. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### type_id Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Ed25519Signature.html Gets the `TypeId` of the Ed25519Signature. This is useful for runtime type identification. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method GET (conceptual) ### Endpoint N/A (method call) ### Parameters None ### Response #### Success Response - **TypeId** (TypeId) - The unique type identifier of the Ed25519Signature instance. ``` -------------------------------- ### Create SpendingPublicKey from Binary Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/impl_mockchain/key/type.SpendingPublicKey.html?search=std%3A%3Avec Provides the method to create a SpendingPublicKey from a byte slice. ```APIDOC ## Implementations ### impl PublicKey #### pub fn from_binary(data: &[u8]) -> Result Creates a PublicKey from a binary representation. ``` -------------------------------- ### Get Chaincode from Bip32PrivateKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PrivateKey.html Retrieves the chain code associated with the Bip32PrivateKey. ```rust pub fn chaincode(&self) -> Vec ``` -------------------------------- ### Read take Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Codec.html?search= Creates an adapter that reads at most a specified limit of bytes from this source. ```rust fn take(self, limit: u64) -> Take ``` -------------------------------- ### type_id Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.Signature.html Gets the TypeId of the Signature. This is useful for runtime type identification. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns A `TypeId` representing the type of the signature. ``` -------------------------------- ### SecretKey Serialization and Deserialization Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.SecretKey.html?search=std%3A%3Avec Shows how to create a SecretKey from binary data and how to convert it to and from Bech32 string representations. ```APIDOC ## SecretKey ### Methods #### `from_binary(data: &[u8]) -> Result` Creates a `SecretKey` from a byte slice. #### `try_from_bech32_str(bech32_str: &str) -> Result` Attempts to create a `SecretKey` from a Bech32 encoded string. #### `to_bech32_str(&self) -> String` Converts the `SecretKey` into a Bech32 encoded string. ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.ScriptHash.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `type_id` method to get the `TypeId` of the ScriptHash type. ```APIDOC ## impl Any for T ### Description Provides the `type_id` method to get the `TypeId` of the ScriptHash type. ### Method `type_id` ### Parameters None ### Response #### Success Response - **TypeId**: The unique identifier for the type. ``` -------------------------------- ### SecretKey Generation and Conversion Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.SecretKey.html?search=std%3A%3Avec Demonstrates how to generate a new SecretKey using a random number generator and how to convert it into its corresponding PublicKey. ```APIDOC ## SecretKey ### Description Represents a secret key used in asymmetric cryptography. ### Methods #### `generate(rng: T) -> Self` Generates a new `SecretKey` using the provided random number generator. #### `to_public(&self) -> PublicKey` Derives the corresponding `PublicKey` from the `SecretKey`. ``` -------------------------------- ### AsRef Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.Signature.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides a way to get a byte slice reference from the Signature. ```APIDOC ## Trait Implementation: AsRef<[u8]> for Signature ### `fn as_ref(&self) -> &[u8]` Converts this type into a shared reference of a byte slice. ``` -------------------------------- ### CloneToUninit Implementation (Nightly) Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/digest/enum.Error.html Performs copy-assignment from self to a raw pointer destination. This is a nightly-only experimental API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) { // ... implementation details ... } ``` -------------------------------- ### Get SecretKey reference from LegacyDaedalusPrivateKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.SecretKey.html?search= Provides a reference to a SecretKey from a LegacyDaedalusPrivateKey. ```rust fn as_ref(&self) -> &SecretKey ``` -------------------------------- ### CloneToUninit Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Ed25519Signature.html?search=u32+-%3E+bool Provides a method to perform copy-assignment from self to an uninitialized destination. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn clone_to_uninit` ### Parameters - `dest` (*mut u8) - A mutable pointer to the destination memory. ### Remarks This is a nightly-only experimental API. ``` -------------------------------- ### Get Raw Bytes from AuxiliaryDataHash Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.AuxiliaryDataHash.html?search=u32+-%3E+bool Returns a slice of the raw bytes representing the AuxiliaryDataHash. ```rust fn to_raw_bytes(&self) -> &[u8] ``` -------------------------------- ### Create Decoder Instance Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/abor/struct.Decoder.html Initializes a new Decoder instance with a reference to a byte slice. This is the entry point for decoding operations. ```rust pub fn new(data: &'a [u8]) -> Self ``` -------------------------------- ### Type ID Method Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/digest/enum.Error.html Gets the TypeId of the Error type. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId { // ... implementation details ... } ``` -------------------------------- ### Get Minimum of Two AuxiliaryDataHash Values Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.AuxiliaryDataHash.html?search=u32+-%3E+bool Compares two AuxiliaryDataHash values and returns the minimum. ```rust fn min(self, other: Self) -> Self where Self: Sized ``` -------------------------------- ### by_ref Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Codec.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a “by reference” adapter for this instance of `Write`. ```APIDOC ## fn by_ref(&mut self) -> &mut Self ### Description Creates a “by reference” adapter for this instance of `Write`. ### Method `by_ref` ``` -------------------------------- ### into_ok Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html?search=u32+-%3E+bool Returns the contained `Ok` value, but never panics. This is a nightly-only experimental API. ```APIDOC ## into_ok ### Description Returns the contained `Ok` value, but never panics. Unlike `unwrap`, this method is known to never panic on the result types it is implemented for. Therefore, it can be used instead of `unwrap` as a maintainability safeguard that will fail to compile if the error type of the `Result` is later changed to an error that can actually occur. ### Method `into_ok()` ### Parameters None ### Request Example ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` ### Response #### Success Response The contained `Ok` value. #### Response Example ```rust "this is fine" ``` ### Note This is a nightly-only experimental API. ``` -------------------------------- ### Get Maximum of Two AuxiliaryDataHash Values Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.AuxiliaryDataHash.html?search=u32+-%3E+bool Compares two AuxiliaryDataHash values and returns the maximum. ```rust fn max(self, other: Self) -> Self where Self: Sized ``` -------------------------------- ### Initialize Encoder Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/abor/struct.Encoder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new instance of the Encoder. ```rust pub fn new() -> Self ``` -------------------------------- ### Get AuxiliaryDataHash JSON Schema Name Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.AuxiliaryDataHash.html?search=u32+-%3E+bool Returns the name of the generated JSON Schema for AuxiliaryDataHash. ```rust fn schema_name() -> String ``` -------------------------------- ### Get TypeId of SecretKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.SecretKey.html Returns the unique TypeId for the SecretKey, useful for runtime type checking. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### KeyPair Implementations Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.KeyPair.html?search=std%3A%3Avec Details the various trait implementations for the KeyPair struct, including Clone, Debug, Display, and From, which enable copying, debugging, display formatting, and creation from a SecretKey. ```APIDOC ## KeyPair Implementations ### `impl Clone for KeyPair` Allows KeyPair instances to be duplicated. ### `impl Debug for KeyPair` Enables debugging output for KeyPair instances. ### `impl Display for KeyPair` Allows KeyPair instances to be formatted for display. ### `impl From> for KeyPair` Provides a way to create a KeyPair directly from a SecretKey. ``` -------------------------------- ### Any Trait Implementation Type ID Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/algorithms/legacy_daedalus/struct.LegacyDaedalus.html Implementation of the Any trait, providing a method to get the TypeId of an object. ```rust fn type_id(&self) -> TypeId; ``` -------------------------------- ### PartialEq Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.Signature.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Allows comparison for equality between Signatures. ```APIDOC ## Trait Implementation: PartialEq for Signature ### `fn eq(&self, other: &Self) -> bool` Tests if two `Signature` instances are equal. ### `fn ne(&self, other: &Rhs) -> bool` Tests if two `Signature` instances are not equal. ``` -------------------------------- ### Get AuxiliaryDataHash Schema ID Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.AuxiliaryDataHash.html?search=u32+-%3E+bool Returns a string that uniquely identifies the JSON Schema produced by AuxiliaryDataHash. ```rust fn schema_id() -> Cow<'static, str> ``` -------------------------------- ### KeyPair Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.KeyPair.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods to interact with a KeyPair, such as retrieving its private and public keys, converting it into a tuple of keys, and generating a new key pair. ```APIDOC ## KeyPair ### Description Represents a cryptographic key pair, consisting of a private and public key. ### Methods #### `fn private_key(&self) -> &SecretKey` Returns a reference to the private key of the KeyPair. #### `fn public_key(&self) -> &PublicKey` Returns a reference to the public key of the KeyPair. #### `fn into_keys(self) -> (SecretKey, PublicKey)` Consumes the KeyPair and returns its private and public keys as a tuple. #### `fn generate(rng: &mut R) -> Self` Generates a new KeyPair using a provided random number generator. ``` -------------------------------- ### Get Next Byte Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next byte from the buffer. The reading position is advanced by one. ```rust pub fn get_u8(&mut self) -> Result ``` -------------------------------- ### Bip32PublicKey::borrow Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html?search=std%3A%3Avec Immutably borrows the Bip32PublicKey. ```APIDOC ## Bip32PublicKey::borrow ### Description Immutably borrows the `Bip32PublicKey`. ### Method `borrow(&self) -> &T` ### Parameters #### Path Parameters - **self** (&self) - Required - The `Bip32PublicKey` to borrow. ``` -------------------------------- ### Bip32PublicKey::clone_from Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html?search=std%3A%3Avec Performs copy-assignment from a source Bip32PublicKey. ```APIDOC ## Bip32PublicKey::clone_from ### Description Performs copy-assignment from a source `Bip32PublicKey`. ### Method `clone_from(&mut self, source: &Self)` ### Parameters #### Path Parameters - **source** (&Self) - Required - The source `Bip32PublicKey` to copy from. ``` -------------------------------- ### Rust Serialize Provided Method: to_canonical_cbor_bytes Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/trait.Serialize.html?search= Provides a method to get canonically encoded CBOR bytes of a structure. ```rust fn to_canonical_cbor_bytes(&self) -> Vec ⓘ Bytes of a structure using the CBOR bytes as per the CDDL spec which for foo = bytes will include the CBOR bytes type/len, etc. This gives the canonically encoded CBOR bytes always ``` -------------------------------- ### Create Bip32PublicKey from Bech32 String Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html Creates a Bip32PublicKey from a Bech32 encoded string. ```rust pub fn from_bech32(bech32_str: &str) -> Result ``` -------------------------------- ### Get Raw Hex String of PublicKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.PublicKey.html?search= Returns a hexadecimal string representation of the PublicKey's raw bytes. ```rust fn to_raw_hex(&self) -> String; ``` -------------------------------- ### KESVkey Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.KESVkey.html?search= Provides methods for key manipulation, conversion to/from Bech32 and hex formats, and accessing byte representations. ```APIDOC ## KESVkey ### Description Represents a Key Encapsulation Secret Value key. ### Methods #### `pub const BYTE_COUNT: usize = 32` - **Description**: The number of bytes in a KESVkey. #### `pub fn to_bech32(&self, prefix: &str) -> Result` - **Description**: Converts the KESVkey to a Bech32 encoded string with the given prefix. - **Parameters**: - `prefix` (str): The Bech32 prefix. - **Returns**: A `Result` containing the Bech32 string or a `CryptoError`. #### `pub fn from_bech32(bech_str: &str) -> Result` - **Description**: Creates a KESVkey from a Bech32 encoded string. - **Parameters**: - `bech_str` (&str): The Bech32 encoded string. - **Returns**: A `Result` containing the `KESVkey` or a `CryptoError`. #### `pub fn to_hex(&self) -> String` - **Description**: Converts the KESVkey to a hexadecimal string. - **Returns**: The hexadecimal string representation of the key. #### `pub fn from_hex(input: &str) -> Result` - **Description**: Creates a KESVkey from a hexadecimal string. - **Parameters**: - `input` (&str): The hexadecimal string. - **Returns**: A `Result` containing the `KESVkey` or a `DeserializeError`. ### Trait Implementations - **Clone**: Allows creating duplicate keys. - **Debug**: Enables debugging output. - **Deserialize**: Supports deserialization from various formats (e.g., JSON, Serde). - **Display**: Allows formatting the key for display. - **From<[u8; 32]>**: Enables conversion from a byte array of 32 bytes. - **From for [u8; 32]**: Enables conversion to a byte array of 32 bytes. - **Hash**: Supports hashing the key. - **JsonSchema**: Generates a JSON schema for the key. - **Ord**: Provides ordering capabilities for keys. - **PartialOrd**: Provides partial ordering capabilities for keys. - **PartialEq**: Enables equality comparison. - **RawBytesEncoding**: Methods for raw byte and hex encoding/decoding. - **Serialize**: Supports serialization to various formats (e.g., JSON, Serde). - **Copy**: Indicates that the key can be copied. - **Eq**: Indicates that the key supports total equality. - **StructuralPartialEq**: Supports structural equality comparison. ``` -------------------------------- ### Get Raw Bytes of PublicKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.PublicKey.html?search= Returns a slice of the raw byte representation of the PublicKey. This is a low-level access method. ```rust fn to_raw_bytes(&self) -> &[u8]; ``` -------------------------------- ### Get Digest of a Slice Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/digest/struct.Digest.html Computes the digest of a given byte slice. This function is part of the Digest implementation. ```rust pub fn digest(slice: &[u8]) -> Self ``` -------------------------------- ### SecretKey Conversion and String Parsing Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.SecretKey.html?search=std%3A%3Avec Illustrates how a SecretKey can be converted into a KeyPair and parsed from a string representation. ```APIDOC ## SecretKey ### Trait Implementations #### `impl From> for KeyPair` Allows conversion of a `SecretKey` into a `KeyPair`. #### `impl FromStr for SecretKey` Enables parsing a `SecretKey` from a string, typically in hexadecimal format. ``` -------------------------------- ### Get Current Position Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Retrieves the current reading position within the ReadBuf. This indicates how many bytes have been consumed. ```rust pub fn position(&self) -> usize ``` -------------------------------- ### Clone Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html?search= Provides methods for cloning Bip32PublicKey instances. ```rust fn clone(&self) -> Bip32PublicKey ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### into_ok Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Returns the contained Ok value, but never panics. This is an experimental API. ```APIDOC ## into_ok ### Description Returns the contained `Ok` value, but never panics. Unlike `unwrap`, this method is known to never panic on the result types it is implemented for. Therefore, it can be used instead of `unwrap` as a maintainability safeguard that will fail to compile if the error type of the `Result` is later changed to an error that can actually occur. ### Method `into_ok()` ### Parameters None ### Request Example ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` ### Response #### Success Response - **T** (type) - The contained Ok value. #### Response Example ```rust "this is fine" ``` ``` -------------------------------- ### Result is_err() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Checks if the Result is the Err variant. Returns true if it is Err, false otherwise. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Bip32PublicKey::serialize Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html?search=std%3A%3Avec Serializes the Bip32PublicKey into a Serde serializer. ```APIDOC ## Bip32PublicKey::serialize ### Description Serializes the `Bip32PublicKey` into the given Serde serializer. ### Method `serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>` ### Parameters #### Path Parameters - **__serializer** (__S) - Required - The Serde serializer. ``` -------------------------------- ### Bip32PublicKey Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html Provides methods for deriving, converting, and accessing information about Bip32PublicKey. ```APIDOC ## Bip32PublicKey Represents a BIP-32 public key. ### Methods #### `derive(index: u32) -> Result` Derives a new Bip32PublicKey using the provided index. **Errors**: Fails if the index is not a soft derivation index (less than 0x80000000). **Security Considerations**: Hard derivation indices cannot be soft derived with a public key. #### `to_raw_key() -> PublicKey` Converts the Bip32PublicKey to its raw PublicKey format. #### `from_bech32(bech32_str: &str) -> Result` Creates a Bip32PublicKey from a Bech32 encoded string. #### `to_bech32() -> String` Converts the Bip32PublicKey to its Bech32 encoded string representation. #### `chaincode() -> Vec` Returns the chain code associated with the Bip32PublicKey. ``` -------------------------------- ### Rust Serialize Provided Method: to_cbor_bytes Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/trait.Serialize.html?search= Provides a method to get CBOR bytes of a structure, including type/length information. ```rust fn to_cbor_bytes(&self) -> Vec ⓘ Bytes of a structure using the CBOR bytes as per the CDDL spec which for foo = bytes will include the CBOR bytes type/len, etc. This gives the original bytes in the case where this was created from bytes originally, or will use whatever the specific encoding details are present in any encoding details struct for the type. ``` -------------------------------- ### Deprecated Description Method Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/enum.Error.html Deprecated method for getting a string description of the error. Users should prefer the Display implementation or to_string(). ```rust fn description(&self) -> &str ``` -------------------------------- ### Serialize Bip32PublicKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html Serializes a Bip32PublicKey into a Serde serializer. ```rust fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer, ``` -------------------------------- ### Display Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.Signature.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides a way to format the Signature for display. ```APIDOC ## Trait Implementation: Display for Signature ### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` Formats the `Signature` value using the given formatter for display purposes. ``` -------------------------------- ### Get Type ID of PrivateKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.PrivateKey.html Retrieves the `TypeId` of the `PrivateKey` instance. This is part of the `Any` trait implementation and is used for runtime type identification. ```rust let type_id = private_key.type_id(); ``` -------------------------------- ### KeyPair Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.KeyPair.html Provides methods to interact with a KeyPair, allowing access to its private and public keys, conversion into a tuple of keys, and generation of new key pairs. ```APIDOC ## KeyPair ### Description A struct that holds a pair of asymmetric cryptographic keys (secret and public). ### Methods #### `fn private_key(&self) -> &SecretKey` Returns a reference to the secret key component of the KeyPair. #### `fn public_key(&self) -> &PublicKey` Returns a reference to the public key component of the KeyPair. #### `fn into_keys(self) -> (SecretKey, PublicKey)` Consumes the KeyPair and returns its secret and public keys as a tuple. #### `fn generate(rng: &mut R) -> Self` Generates a new KeyPair using the provided random number generator. ``` -------------------------------- ### Signature Implementations Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/impl_mockchain/key/type.Ed25519Signature.html?search=std%3A%3Avec Provides methods for interacting with Signature types, including creation, coercion, and verification. ```APIDOC ## Signature Implementations ### `from_binary` Creates a signature from a binary slice. #### Signature ```rust pub fn from_binary(sig: &[u8]) -> Result ``` ### `coerce` Coerces the signature to a different type `U`. #### Signature ```rust pub fn coerce(self) -> Signature ``` ### `safe_coerce` Safely coerces the signature to a different type `U` that implements `SafeSignatureCoerce`. #### Signature ```rust pub fn safe_coerce>(self) -> Signature ``` ### `verify` Verifies the signature against a public key and an object. #### Signature ```rust pub fn verify(&self, publickey: &PublicKey, object: &T) -> Verification ``` ### `verify_slice` Verifies the signature against a public key and a byte slice. #### Signature ```rust pub fn verify_slice( &self, publickey: &PublicKey, slice: &[u8], ) -> Verification ``` ``` -------------------------------- ### Rust Result unwrap_err() - Err Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Demonstrates `unwrap_err()` returning the contained `Err` value when called on a `Result` that holds an `Err`. ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Codec Implementations Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Codec.html?search=std%3A%3Avec Provides methods for creating a Codec instance and retrieving its inner value. ```APIDOC ## impl Codec ### new Creates a new Codec instance with the given inner value. ```rust pub fn new(inner: I) -> Self ``` ### into_inner Consumes the Codec and returns the inner value. ```rust pub fn into_inner(self) -> I ``` ``` -------------------------------- ### Result is_err_and() Method Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Checks if the Result is Err and its value satisfies a given predicate. Returns false if the Result is Ok. ```rust let x: Result = Ok(2); assert_eq!(x.is_err_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_err_and(|x| x.len() > 1), true); ``` -------------------------------- ### KeyPair Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.KeyPair.html?search=std%3A%3Avec Provides methods to interact with a KeyPair, such as retrieving its private and public keys, converting it into a tuple of keys, and generating a new KeyPair using a random number generator. ```APIDOC ## KeyPair ### Description Represents a cryptographic key pair, consisting of a private and public key. ### Methods #### `fn private_key(&self) -> &SecretKey` Returns a reference to the private key of the KeyPair. #### `fn public_key(&self) -> &PublicKey` Returns a reference to the public key of the KeyPair. #### `fn into_keys(self) -> (SecretKey, PublicKey)` Consumes the KeyPair and returns its private and public keys as a tuple. #### `fn generate(rng: &mut R) -> Self` Generates a new KeyPair using the provided random number generator. ``` -------------------------------- ### TryFrom for T Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/digest/enum.Error.html A blanket implementation of TryFrom for T. Part of blanket implementations. ```rust type Error = Infallible; fn try_from(value: U) -> Result>::Error> { // ... implementation details ... } ``` -------------------------------- ### Rust CloneToUninit Implementation (Nightly) Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/enum.Verification.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E An experimental, nightly-only API for performing copy-assignment from a `Clone` type to an uninitialized memory location. Use with caution. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) // ... implementation details ... ``` -------------------------------- ### Buffered Implementations: Get Bytes Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Buffered.html?search=std%3A%3Avec Retrieves a specified number of bytes from the buffered writer. This operation returns a Vec and may result in an error. ```rust pub fn get_bytes(&mut self, n: usize) -> Result> ``` -------------------------------- ### Sign to Create ByronProxySecretKey Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/byron_proxy_key/struct.ByronProxySecretKey.html Creates a ByronProxySecretKey by signing the delegate public key and omega using the issuer's private key and the specified protocol magic. ```rust pub fn sign( issuer_prv: &SecretKey, delegate_pk: PublicKey, omega: u64, protocol_magic: ProtocolMagic, ) -> Self ``` -------------------------------- ### Get Remaining Slice Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Retrieves a slice containing all remaining bytes in the buffer from the current position to the end. The reading position is advanced to the end of the buffer. ```rust pub fn get_slice_end(&mut self) -> &'a [u8] ``` -------------------------------- ### Unsafe `unwrap_unchecked` on Err (Undefined Behavior) Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html?search= Demonstrates the unsafe `unwrap_unchecked` method. Calling this on an `Err` value results in undefined behavior, as shown in this example. ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` -------------------------------- ### ByteBuilder::new Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/typed_bytes/struct.ByteBuilder.html?search= Creates a new, unconstrained ByteBuilder. This builder can grow dynamically without a predefined size limit. ```APIDOC ## ByteBuilder::new ### Description Creates an unconstrained ByteBuilder. ### Method `new()` ### Returns - `Self`: A new, empty ByteBuilder instance. ``` -------------------------------- ### Clone Implementation for Priv Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/algorithms/ed25519/struct.Priv.html Enables creating a copy of a `Priv` key. This is useful for scenarios where the original key needs to be preserved. ```rust fn clone(&self) -> Priv ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Buffered Implementations Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Buffered.html?search=u32+-%3E+bool Provides methods for interacting with the Buffered struct, such as creating holes for data, filling holes with specific types, and getting the current buffered length. ```rust pub fn hole(&mut self, len: usize) -> Result> ``` ```rust pub fn into_inner(self) -> Result> ``` ```rust pub fn fill_hole_u8(&mut self, hole: Hole, value: u8) ``` ```rust pub fn fill_hole_u16(&mut self, hole: Hole, value: u16) ``` ```rust pub fn fill_hole_u32(&mut self, hole: Hole, value: u32) ``` ```rust pub fn fill_hole_u64(&mut self, hole: Hole, value: u64) ``` ```rust pub fn fill_hole_u128(&mut self, hole: Hole, value: u128) ``` ```rust pub fn buffered_len(&self) -> usize ``` -------------------------------- ### Bip32PublicKey::from_bech32 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.Bip32PublicKey.html?search=u32+-%3E+bool Creates a Bip32PublicKey from a Bech32 encoded string. ```APIDOC ## pub fn from_bech32(bech32_str: &str) -> Result ### Description Creates a Bip32PublicKey from a Bech32 encoded string. ### Parameters #### Path Parameters - **bech32_str** (&str) - Required - The Bech32 encoded string. ``` -------------------------------- ### Buffered Implementations: Buffer Information Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Buffered.html?search= Provides methods to get information about the buffered data. These methods are part of the impl Buffered block. ```rust pub fn buffered_len(&self) -> usize ``` -------------------------------- ### Create a sub-builder using a closure Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/typed_bytes/struct.ByteBuilder.html The `sub()` method allows creating a nested `ByteBuilder` using a closure. The closure receives a new `ByteBuilder` and should return a `ByteBuilder` that will be appended to the current builder. ```rust pub fn sub(self, f: F) -> Self where F: Fn(ByteBuilder) -> ByteBuilder, ``` -------------------------------- ### Get Next U128 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next sixteen bytes from the buffer as a u128. The reading position is advanced by sixteen. Assumes little-endian byte order. ```rust pub fn get_u128(&mut self) -> Result ``` -------------------------------- ### Get Next U64 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next eight bytes from the buffer as a u64. The reading position is advanced by eight. Assumes little-endian byte order. ```rust pub fn get_u64(&mut self) -> Result ``` -------------------------------- ### ByteSlice Blanket Implementations Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/typed_bytes/struct.ByteSlice.html?search= Demonstrates blanket implementations for ByteSlice, including Any, Base32Len, Borrow, BorrowMut, CheckBase32, and CloneToUninit. These provide common functionalities based on underlying traits. ```rust impl Any for T where T: 'static + ?Sized ``` ```rust impl Base32Len for T where T: AsRef<[u8]> ``` ```rust impl Borrow for T where T: ?Sized ``` ```rust impl BorrowMut for T where T: ?Sized ``` ```rust impl<'f, T> CheckBase32> for T where T: AsRef<[u8]> ``` ```rust impl CloneToUninit for T where T: Clone ``` -------------------------------- ### Get Next U32 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next four bytes from the buffer as a u32. The reading position is advanced by four. Assumes little-endian byte order. ```rust pub fn get_u32(&mut self) -> Result ``` -------------------------------- ### KeyPair Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.KeyPair.html?search=u32+-%3E+bool Provides methods for interacting with KeyPair objects, such as retrieving keys or generating new pairs. ```APIDOC ## KeyPair ### Description Represents a cryptographic key pair consisting of a secret key and a public key. ### Methods #### `fn private_key(&self) -> &SecretKey` Returns a reference to the secret key component of the key pair. #### `fn public_key(&self) -> &PublicKey` Returns a reference to the public key component of the key pair. #### `fn into_keys(self) -> (SecretKey, PublicKey)` Consumes the `KeyPair` and returns its secret and public keys as a tuple. #### `fn generate(rng: &mut R) -> Self` Generates a new `KeyPair` using the provided random number generator. ``` -------------------------------- ### Get Next U16 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next two bytes from the buffer as a u16. The reading position is advanced by two. Assumes little-endian byte order. ```rust pub fn get_u16(&mut self) -> Result ``` -------------------------------- ### TryInto for T Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/digest/enum.Error.html A blanket implementation of TryInto for T. Part of blanket implementations. ```rust type Error = >::Error; fn try_into(self) -> Result>::Error> { // ... implementation details ... } ``` -------------------------------- ### PartialEq Implementation for Pub Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/algorithms/ed25519/struct.Pub.html Compares two Ed25519 public keys for equality. ```rust fn eq(&self, other: &Pub) -> bool ``` -------------------------------- ### Clone Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.Signature.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Allows creating copies of the Signature. ```APIDOC ## Trait Implementation: Clone for Signature ### `fn clone(&self) -> Self` Returns a duplicate of the `Signature`. ### `fn clone_from(&mut self, source: &Self)` Performs copy-assignment from a source `Signature`. ``` -------------------------------- ### RawBytesEncoding Trait Definition Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/trait.RawBytesEncoding.html Defines the core methods for raw byte encoding and decoding. Use `to_raw_bytes` to get the byte slice and `from_raw_bytes` to construct an object from bytes. ```rust pub trait RawBytesEncoding { // Required methods fn to_raw_bytes(&self) -> &[u8]; fn from_raw_bytes(bytes: &[u8]) -> Result where Self: Sized; // Provided methods fn to_raw_hex(&self) -> String { ... } fn from_raw_hex(hex_str: &str) -> Result where Self: Sized { ... } } ``` -------------------------------- ### Unwrap a Result to get T Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/hash/type.Result.html?search=std%3A%3Avec Unwraps a Result, yielding the contained Ok value. Panics if the value is an Err, with a panic message provided by the Err's value. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### Getting a mutable reference with as_mut() Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html The `as_mut()` method converts a `&mut Result` into a `Result<&mut T, &mut E>`, allowing in-place modification of the contained values. ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### PublicKey from_binary Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.PublicKey.html?search= Provides a method to create a PublicKey from a byte slice. This is useful for deserializing public keys from binary data. ```rust pub fn from_binary(data: &[u8]) -> Result ``` -------------------------------- ### PrivateKey Methods Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/struct.PrivateKey.html?search= This section details the public methods available for the PrivateKey struct, allowing for key generation, conversion, and signing. ```APIDOC ## PrivateKey Methods ### `to_public()` Converts the private key to its corresponding public key. ### `generate_ed25519()` Generates a new Ed25519 private key. ### `generate_ed25519extended()` Generates a new extended Ed25519 private key. ### `from_bech32(bech32_str: &str)` **Description**: Get private key from its bech32 representation. **Example**: ```rust use cml_crypto::PrivateKey; let key = PrivateKey::from_bech32("ed25519_sk1ahfetf02qwwg4dkq7mgp4a25lx5vh9920cr5wnxmpzz9906qvm8qwvlts0").unwrap(); ``` **Extended Key Example**: ```rust use cml_crypto::PrivateKey; let key = PrivateKey::from_bech32("ed25519e_sk1gqwl4szuwwh6d0yk3nsqcc6xxc3fpvjlevgwvt60df59v8zd8f8prazt8ln3lmz096ux3xvhhvm3ca9wj2yctdh3pnw0szrma07rt5gl748fp").unwrap(); ``` ### `to_bech32()` Converts the private key to its bech32 string representation. ### `from_extended_bytes(bytes: &[u8])` Creates a PrivateKey from extended byte slice. ### `from_normal_bytes(bytes: &[u8])` Creates a PrivateKey from a normal byte slice. ### `sign(message: &[u8])` Signs a message using the private key, returning an Ed25519Signature. ``` -------------------------------- ### Digest from Object Implementing AsRef<[u8]> Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/digest/struct.DigestOf.html?search=std%3A%3Avec Computes the digest of an object T that implements AsRef<[u8]>. This is a common way to get the digest of types that can be represented as byte slices. ```rust pub fn digest(obj: &T) -> Self where T: AsRef<[u8]> ``` -------------------------------- ### Get Next Non-Zero U64 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next eight bytes from the buffer as a NonZeroU64. The reading position is advanced by eight. Assumes little-endian byte order. ```rust pub fn get_nz_u64(&mut self) -> Result ``` -------------------------------- ### Blanket Implementations: From and Into Traits Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/packer/struct.Buffered.html?search= Illustrates the blanket implementations of `From` for `T` and `Into` for `T` where `U` implements `From`, enabling type conversions. ```rust fn from(t: T) -> T ``` ```rust fn into(self) -> U ``` -------------------------------- ### Bech32 Implementation Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/struct.Signature.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Enables Bech32 encoding and decoding for the Signature. ```APIDOC ## Trait Implementation: Bech32 for Signature ### `const BECH32_HRP: &'static str` The human-readable part for Bech32 encoding, derived from `A::SIGNATURE_BECH32_HRP`. ### `fn try_from_bech32_str(bech32_str: &str) -> Result` Attempts to create a `Signature` from a Bech32 encoded string. ### `fn to_bech32_str(&self) -> String` Converts the `Signature` into a Bech32 encoded string. ``` -------------------------------- ### Get Next Non-Zero U32 Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_core/mempack/struct.ReadBuf.html Reads and consumes the next four bytes from the buffer as a NonZeroU32. The reading position is advanced by four. Assumes little-endian byte order. ```rust pub fn get_nz_u32(&mut self) -> Result ``` -------------------------------- ### PartialEq Implementation for Pub Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/algorithms/ed25519/struct.Pub.html?search=std%3A%3Avec Defines equality comparison for Pub instances. ```rust fn eq(&self, other: &Pub) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Rust Result unwrap_err() - Ok Example (Panics) Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Shows `unwrap_err()` panicking when called on a `Result` containing an `Ok` value. The panic message is the `Ok`'s value. ```rust let x: Result = Ok(2); x.unwrap_err(); // panics with `2` ``` -------------------------------- ### Result flatten() Method - Multiple Levels Example Source: https://docs.rs/cml-crypto/6.2.0/cml_crypto/chain_crypto/bech32/type.Result.html Illustrates that flatten() removes only one level of nesting at a time, requiring multiple calls for deeply nested Results. ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ```