Skip to content

Commit d7e0831

Browse files
committed
EndpointScope: Extract TryFrom<&[u8]> for EndpointScope trait
1 parent 0d160e8 commit d7e0831

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/models/token/scopes.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,22 @@ impl ToSql<Text, Pg> for EndpointScope {
3131
}
3232
}
3333

34-
impl FromSql<Text, Pg> for EndpointScope {
35-
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
36-
match not_none!(bytes) {
34+
impl TryFrom<&[u8]> for EndpointScope {
35+
type Error = String;
36+
37+
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
38+
match bytes {
3739
b"publish-new" => Ok(EndpointScope::PublishNew),
3840
b"publish-update" => Ok(EndpointScope::PublishUpdate),
3941
b"yank" => Ok(EndpointScope::Yank),
4042
b"change-owners" => Ok(EndpointScope::ChangeOwners),
41-
_ => Err("Unrecognized enum variant".into()),
43+
_ => Err("Unrecognized enum variant".to_string()),
4244
}
4345
}
4446
}
47+
48+
impl FromSql<Text, Pg> for EndpointScope {
49+
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
50+
Ok(EndpointScope::try_from(not_none!(bytes))?)
51+
}
52+
}

0 commit comments

Comments
 (0)