Skip to content

Commit b528349

Browse files
committed
Implement FromStr for Name and Identifier
1 parent 6351783 commit b528349

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/identifier.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::hash::Hash;
2+
use std::str::FromStr;
23
use std::sync::Arc;
34

45
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
@@ -90,6 +91,14 @@ impl std::borrow::Borrow<str> for Identifier {
9091
}
9192
}
9293

94+
impl FromStr for Identifier {
95+
type Err = ErrorKind;
96+
97+
fn from_str(s: &str) -> Result<Self, Self::Err> {
98+
Identifier::new(s)
99+
}
100+
}
101+
93102
impl Serialize for Identifier {
94103
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
95104
where

src/name.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Glyph and layer names
22
3+
use std::str::FromStr;
34
use std::sync::Arc;
45

56
use serde::{Deserialize, Deserializer};
@@ -93,6 +94,14 @@ impl std::borrow::Borrow<str> for Name {
9394
}
9495
}
9596

97+
impl FromStr for Name {
98+
type Err = NamingError;
99+
100+
fn from_str(s: &str) -> Result<Self, Self::Err> {
101+
Name::new(s)
102+
}
103+
}
104+
96105
impl<'de> Deserialize<'de> for Name {
97106
fn deserialize<D>(deserializer: D) -> Result<Name, D::Error>
98107
where

0 commit comments

Comments
 (0)