Fix JSON serialization
We recently removed the custom serialization for InputSource.
This causes the JSON formatter to fail
with "key must be a string".
Add it back and add a comment on
why this is needed.
@@ -43,7 +43,7 @@ impl InputContent {
}
}
-#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
/// Input types which lychee supports
pub enum InputSource {
@@ -64,6 +64,18 @@ pub enum InputSource {
String(String),
}
+// Custom serialization for enum is needed
+// Otherwise we get "key must be a string" when using the JSON writer
+// Related: https://github.com/serde-rs/json/issues/45
+impl Serialize for InputSource {
+ fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ serializer.collect_str(self)
+ }
+}
+
impl Display for InputSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
