impl FromStr for StringKey
@@ -13,6 +13,7 @@ use parking_lot::RwLock;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::num::NonZeroU32;
+use std::str::FromStr;
use std::sync::Arc;
/// Slices of bytes intern as BytesKey
@@ -77,6 +78,14 @@ impl PartialOrd for StringKey {
}
}
+impl FromStr for StringKey {
+ type Err = std::convert::Infallible;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ Ok(s.intern())
+ }
+}
+
impl StringKey {
/// Get a reference to the original str.
pub fn lookup(self) -> &'static str {
