~jpastuszek/maybe-string

ba20f69711f5b8471ef3d971a97fd26b205635b2 — Jakub Pastuszek a month ago dac0924 0.1.0
more trait derives and impls
1 files changed, 17 insertions(+), 3 deletions(-)

M src/lib.rs
M src/lib.rs => src/lib.rs +17 -3
@@ 47,14 47,14 @@ use std::fmt::{self, Debug, Display};
use std::ops::Deref;
use std::str::FromStr;
use std::convert::Infallible;
use std::borrow::Cow;
use std::borrow::{Borrow, Cow};

#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};

/// A newtype wrapper that represents a byte vector that may be a valid UTF-8 string.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Default, Clone)]
pub struct MaybeString(pub Vec<u8>);

impl MaybeString {


@@ 105,6 105,12 @@ impl Deref for MaybeString {
    }
}

impl Borrow<MaybeStr> for MaybeString {
    fn borrow(&self) -> &MaybeStr {
        self.as_ref()
    }
}

impl AsRef<MaybeStr> for MaybeString {
    fn as_ref(&self) -> &MaybeStr {
        self


@@ 163,7 169,7 @@ impl FromStr for MaybeString {

/// [MaybeString] slices.
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(PartialEq)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MaybeStr([u8]);

impl MaybeStr {


@@ 228,6 234,14 @@ impl AsRef<[u8]> for MaybeStr {
    }
}

impl ToOwned for MaybeStr {
    type Owned = MaybeString;

    fn to_owned(&self) -> Self::Owned {
        self.to_maybe_string()
    }
}

impl<'b> From<&'b [u8]> for &'b MaybeStr {
    fn from(data: &[u8]) -> &MaybeStr {
        MaybeStr::from_bytes(data)