Skip to content

Commit

Permalink
feat(feed): impl Display for annotation types
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Apr 13, 2024
1 parent 510106b commit d68aa81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion crates/synd_feed/src/types/category.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::borrow::Cow;
use std::{
borrow::Cow,
fmt::{self, Display},
};

use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -37,6 +40,12 @@ impl<'a> Category<'a> {
}
}

impl<'a> Display for Category<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.0.as_ref())
}
}

#[cfg(feature = "graphql")]
#[async_graphql::Scalar]
impl<'s> async_graphql::ScalarType for Category<'s> {
Expand Down
15 changes: 14 additions & 1 deletion crates/synd_feed/src/types/requirement.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use std::{
fmt::{self, Display},
str::FromStr,
};

/// `Requirement` expresses how important the feed is
/// using an analogy to [RFC2119](https://datatracker.ietf.org/doc/html/rfc2119)
Expand All @@ -26,3 +29,13 @@ impl FromStr for Requirement {
}
}
}

impl Display for Requirement {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result {
match self {
Requirement::Must => f.write_str("MUST"),
Requirement::Should => f.write_str("SHOULD"),
Requirement::May => f.write_str("MAY"),
}
}
}

0 comments on commit d68aa81

Please sign in to comment.