Skip to content

Commit

Permalink
Minor correction for serialisation of ColumnRef (#188)
Browse files Browse the repository at this point in the history
This puts in a minor correction in order to keep consistency with
serlisation of `Handle`.
  • Loading branch information
DavePearce authored Jun 10, 2024
1 parent 8d36db8 commit de82d74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/compiler/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ impl Serialize for ColumnRef {
fn serialize<S: serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let fmt_str = match (&self.h, &self.id) {
(None, None) => unreachable!(),
(Some(h), None) => format!("{}", h),
(Some(h), None) => format!("{}", h.to_serialize_string()),
(None, Some(id)) => format!("#{}", id),
(Some(h), Some(id)) => format!("{}#{}", h, id),
(Some(h), Some(id)) => format!("{}#{}", h.to_serialize_string(), id),
};
// Done
serializer.serialize_str(&fmt_str)
Expand Down
18 changes: 12 additions & 6 deletions src/structs/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ impl std::fmt::Display for Handle {
}

#[cfg(feature = "json-bin")]
impl Serialize for Handle {
fn serialize<S: serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
impl Handle {
pub fn to_serialize_string(&self) -> String {
// Sanity checks
assert!(
!self.module.contains(":"),
Expand All @@ -187,13 +187,19 @@ impl Serialize for Handle {
!self.perspective.as_ref().map_or(false, |s| s.contains(":")),
"JSON deserisalisation conflict on perspective"
);
// Compute format string
let fmt_str = match &self.perspective {
//
match &self.perspective {
None => format!("{}:{}", self.module, self.name),
Some(p) => format!("{}:{}:{}", self.module, self.name, p),
};
}
}
}

#[cfg(feature = "json-bin")]
impl Serialize for Handle {
fn serialize<S: serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// Done
serializer.serialize_str(&fmt_str)
serializer.serialize_str(&self.to_serialize_string())
}
}

Expand Down

0 comments on commit de82d74

Please sign in to comment.