Skip to content

Commit 0d160e8

Browse files
committed
EndpointScope: Extract From<&EndpointScope> for &[u8] trait
1 parent 413ae86 commit 0d160e8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/models/token/scopes.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ pub enum EndpointScope {
1313
ChangeOwners,
1414
}
1515

16+
impl From<&EndpointScope> for &[u8] {
17+
fn from(scope: &EndpointScope) -> Self {
18+
match scope {
19+
EndpointScope::PublishNew => b"publish-new",
20+
EndpointScope::PublishUpdate => b"publish-update",
21+
EndpointScope::Yank => b"yank",
22+
EndpointScope::ChangeOwners => b"change-owners",
23+
}
24+
}
25+
}
26+
1627
impl ToSql<Text, Pg> for EndpointScope {
1728
fn to_sql<W: Write>(&self, out: &mut Output<'_, W, Pg>) -> serialize::Result {
18-
match *self {
19-
EndpointScope::PublishNew => out.write_all(b"publish-new")?,
20-
EndpointScope::PublishUpdate => out.write_all(b"publish-update")?,
21-
EndpointScope::Yank => out.write_all(b"yank")?,
22-
EndpointScope::ChangeOwners => out.write_all(b"change-owners")?,
23-
}
29+
out.write_all(self.into())?;
2430
Ok(IsNull::No)
2531
}
2632
}

0 commit comments

Comments
 (0)