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>
impl<'de, T, ALPHABET> DeserializeAs<'de, T> for Base58<ALPHABET>
Source§fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error>where
D: Deserializer<'de>,
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.
impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>
Available on crate feature
schemars_0_8 only.Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
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
fn json_schema(_: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moreSource§impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>
Available on crate feature schemars_0_9 only.
impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>
Available on crate feature
schemars_0_9 only.Source§fn schema_id() -> Cow<'static, str>
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
fn json_schema(_: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
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 moreSource§impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>
Available on crate feature schemars_1 only.
impl<T, A: Alphabet> JsonSchemaAs<T> for Base58<A>
Available on crate feature
schemars_1 only.Source§fn schema_id() -> Cow<'static, str>
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
fn json_schema(_: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
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 moreSource§impl<T, ALPHABET> SerializeAs<T> for Base58<ALPHABET>
impl<T, ALPHABET> SerializeAs<T> for Base58<ALPHABET>
Source§fn serialize_as<S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more