Struct vtubestudio::data::EnumString
source · [−]pub struct EnumString<T>(_);
Expand description
Wrapper type for an enum
with a serialized string representation.
This allows for defining an enum
with a set of known values, but still accept other arbitrary
string values when serializing/deserializing.
Example
use vtubestudio::data::{EnumString, ResponseType};
// Multiple representations of the same enum
let resp_enum = EnumString::new(ResponseType::VtsFolderInfoResponse);
let resp_str = EnumString::new_from_str("VTSFolderInfoResponse");
// Can be compared to the inner enum type and other `EnumString`s
assert_eq!(resp_enum, ResponseType::VtsFolderInfoResponse);
assert_eq!(resp_str, ResponseType::VtsFolderInfoResponse);
assert_eq!(resp_enum, resp_str);
// Get the string representation of the enum
assert_eq!(resp_enum.as_str(), "VTSFolderInfoResponse");
assert_eq!(resp_str.as_str(), "VTSFolderInfoResponse");
Implementations
sourceimpl EnumString<ResponseType>
impl EnumString<ResponseType>
sourceimpl<T> EnumString<T>
impl<T> EnumString<T>
sourcepub fn new_from_str<S>(value: S) -> Selfwhere
S: Into<Cow<'static, str>>,
pub fn new_from_str<S>(value: S) -> Selfwhere
S: Into<Cow<'static, str>>,
Creates a new value from a raw string.
sourcepub const fn const_new_from_str(value: &'static str) -> Self
pub const fn const_new_from_str(value: &'static str) -> Self
Creates a new value from a const
static string slice.
Trait Implementations
sourceimpl<T: Clone> Clone for EnumString<T>
impl<T: Clone> Clone for EnumString<T>
sourcefn clone(&self) -> EnumString<T>
fn clone(&self) -> EnumString<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<T: Debug> Debug for EnumString<T>
impl<T: Debug> Debug for EnumString<T>
sourceimpl<T: Default> Default for EnumString<T>
impl<T: Default> Default for EnumString<T>
sourcefn default() -> EnumString<T>
fn default() -> EnumString<T>
Returns the “default value” for a type. Read more
sourceimpl<'de, T> Deserialize<'de> for EnumString<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for EnumString<T>where
T: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T> Display for EnumString<T>where
T: Serialize,
impl<T> Display for EnumString<T>where
T: Serialize,
sourceimpl<T> From<T> for EnumString<T>where
T: Serialize + PartialEq,
impl<T> From<T> for EnumString<T>where
T: Serialize + PartialEq,
sourceimpl<T> PartialEq<EnumString<T>> for EnumString<T>where
T: Serialize + PartialEq,
impl<T> PartialEq<EnumString<T>> for EnumString<T>where
T: Serialize + PartialEq,
Auto Trait Implementations
impl<T> RefUnwindSafe for EnumString<T>where
T: RefUnwindSafe,
impl<T> Send for EnumString<T>where
T: Send,
impl<T> Sync for EnumString<T>where
T: Sync,
impl<T> Unpin for EnumString<T>where
T: Unpin,
impl<T> UnwindSafe for EnumString<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more