CidExt

Trait CidExt 

Source
pub trait CidExt {
    // Required methods
    fn to_string_with_base(&self, base: MultibaseEncoding) -> String;
    fn to_v1(&self) -> Result<Cid>;
    fn to_v0(&self) -> Result<Cid>;
    fn can_be_v0(&self) -> bool;
    fn is_v0(&self) -> bool;
    fn is_v1(&self) -> bool;
    fn codec_code(&self) -> u64;
    fn hash_algorithm_name(&self) -> &'static str;
    fn hash_algorithm_code(&self) -> u64;
}
Expand description

Extension trait for CID with additional encoding utilities

Required Methods§

Source

fn to_string_with_base(&self, base: MultibaseEncoding) -> String

Encode the CID to a string with the specified multibase encoding

Source

fn to_v1(&self) -> Result<Cid>

Convert CIDv0 to CIDv1

CIDv0 is converted to CIDv1 with DAG-PB codec (0x70)

Source

fn to_v0(&self) -> Result<Cid>

Try to convert CIDv1 to CIDv0

This only succeeds if:

  • The hash algorithm is SHA2-256
  • The codec is DAG-PB (0x70)
Source

fn can_be_v0(&self) -> bool

Check if this CID can be represented as CIDv0

Returns true if the CID uses SHA2-256 and DAG-PB codec

Source

fn is_v0(&self) -> bool

Check if this is a CIDv0

Source

fn is_v1(&self) -> bool

Check if this is a CIDv1

Source

fn codec_code(&self) -> u64

Get the codec code

Source

fn hash_algorithm_name(&self) -> &'static str

Get the hash algorithm name

Source

fn hash_algorithm_code(&self) -> u64

Get the hash algorithm code

Implementors§