[][src]Trait hex_buffer_serde::Hex

pub trait Hex<T> {
    pub fn create_bytes(value: &T) -> Cow<'_, [u8]>;
pub fn from_bytes(bytes: &[u8]) -> Result<T, String>; pub fn serialize<S: Serializer>(
        value: &T,
        serializer: S
    ) -> Result<S::Ok, S::Error> { ... }
pub fn deserialize<'de, D>(deserializer: D) -> Result<T, D::Error>
    where
        D: Deserializer<'de>
, { ... } }

Provides hex-encoded (de)serialization for serde.

Note that the trait is automatically implemented for types that implement AsRef<[u8]> and TryFrom<&[u8]>.

Required methods

pub fn create_bytes(value: &T) -> Cow<'_, [u8]>[src]

Converts the value into bytes. This is used for serialization.

The returned buffer can be either borrowed from the type, or created by the method.

pub fn from_bytes(bytes: &[u8]) -> Result<T, String>[src]

Creates a value from the byte slice.

Errors

If this method fails, it should return a human-readable error description conforming to serde conventions (no upper-casing of the first letter, no punctuation at the end).

Loading content...

Provided methods

pub fn serialize<S: Serializer>(
    value: &T,
    serializer: S
) -> Result<S::Ok, S::Error>
[src]

Serializes the value for serde. This method is not meant to be overridden.

The serialization is a lower-case hex string for human-readable serializers (e.g., JSON or TOML), and the original bytes returned by Self::create_bytes() for non-human-readable ones.

pub fn deserialize<'de, D>(deserializer: D) -> Result<T, D::Error> where
    D: Deserializer<'de>, 
[src]

Deserializes a value using serde. This method is not meant to be overridden.

If the deserializer is human-readable (e.g., JSON or TOML), this method expects a hex-encoded string. Otherwise, the method expects a byte array.

Loading content...

Implementors

impl<T> Hex<T> for HexForm<T> where
    T: AsRef<[u8]> + for<'a> TryFrom<&'a [u8]>,
    <T as TryFrom<&'a [u8]>>::Error: ToString
[src]

Loading content...