Skip to main content

Module encoded

Module encoded 

Source
Expand description

Validated multibase-encoded strings.

This module provides the EncodedString type, a newtype wrapper that guarantees a string is a valid multibase-encoded value with a recognized base code prefix.

§Type Safety

Following the “parse, don’t validate” principle, EncodedString ensures that once created, the string is guaranteed to:

  • Have a valid base code prefix
  • Be parseable (though decoding may still fail if the data is malformed)

§Examples

use multi_base::{EncodedString, Base};

// Parse and validate a multibase string
let encoded = EncodedString::new("zCn8eVZg").unwrap();
assert_eq!(encoded.base(), Base::Base58Btc);

// Decode the validated string
let decoded = encoded.decode().unwrap();
assert_eq!(decoded, b"hello");

// Access the underlying string
assert_eq!(encoded.as_str(), "zCn8eVZg");

Structs§

EncodedString
A validated multibase-encoded string.