Skip to main content

StringNewtype

Derive Macro StringNewtype 

Source
#[derive(StringNewtype)]
Expand description

Derive macro that generates the same boilerplate as the string_newtype! declarative macro. Apply to a tuple struct wrapping a single String field.

Generates:

  • Inherent methods: new(), as_str(), into_inner()
  • Deref<Target = str>
  • Borrow<str>
  • AsRef<str>
  • Display
  • From<String>, From<&str>, From<Self> for String

§Example

#[derive(Debug, Clone, Serialize, Deserialize, StringNewtype)]
#[serde(transparent)]
pub struct SessionId(String);