Skip to main content

Base58

Struct Base58 

Source
pub struct Base58<ALPHABET: Alphabet = Standard>(/* private fields */);
Available on crate feature base58 only.
Expand description

Serialize bytes with base58

The type serializes a sequence of bytes as a base58 string. It works on any type implementing AsRef<[u8]> for serialization and TryFrom<Vec<u8>> for deserialization.

The type allows customizing the character set. The ALPHABET is a type implementing Alphabet.

use serde_with::base58::{Base58, Flickr};

#[serde_as]
#[derive(Serialize, Deserialize)]
struct B58 {
    // The default is the same as Standard character set
    #[serde_as(as = "Base58")]
    default: Vec<u8>,
    // Change the character set
    #[serde_as(as = "Base58<Flickr>")]
    charset_flickr: Vec<u8>,
}

let b58 = B58 {
    default: b"Hello World".to_vec(),
    charset_flickr: b"Hello World".to_vec(),
};
let json = serde_json::json!({
    "default": "JxF12TrwUP45BMd",
    "charset_flickr": "iXf12sRWto45bmC",
});

// Test serialization and deserialization
assert_eq!(json, serde_json::to_value(&b58).unwrap());
assert_eq!(b58, serde_json::from_value(json).unwrap());

Trait Implementations§

Source§

impl<'de, T, ALPHABET> DeserializeAs<'de, T> for Base58<ALPHABET>
where T: TryFrom<Vec<u8>>, ALPHABET: Alphabet,

Source§

fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer.
Source§

impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>

Available on crate feature schemars_0_8 only.
Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>

Available on crate feature schemars_0_9 only.
Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON schemas generated for this type should be included directly in arent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>

Available on crate feature schemars_1 only.
Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON schemas generated for this type should be included directly in arent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl<T, ALPHABET> SerializeAs<T> for Base58<ALPHABET>
where T: AsRef<[u8]>, ALPHABET: Alphabet,

Source§

fn serialize_as<S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer.

Auto Trait Implementations§

§

impl<ALPHABET> Freeze for Base58<ALPHABET>

§

impl<ALPHABET> RefUnwindSafe for Base58<ALPHABET>
where ALPHABET: RefUnwindSafe,

§

impl<ALPHABET> Send for Base58<ALPHABET>
where ALPHABET: Send,

§

impl<ALPHABET> Sync for Base58<ALPHABET>
where ALPHABET: Sync,

§

impl<ALPHABET> Unpin for Base58<ALPHABET>
where ALPHABET: Unpin,

§

impl<ALPHABET> UnsafeUnpin for Base58<ALPHABET>

§

impl<ALPHABET> UnwindSafe for Base58<ALPHABET>
where ALPHABET: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.