Skip to content

Commit

Permalink
add extended support, supports uuid and naivedatetime
Browse files Browse the repository at this point in the history
  • Loading branch information
mvntainer committed Aug 9, 2023
1 parent a93f66f commit 0b38e26
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sailfish/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ default = ["config", "derive", "perf-inline"]
config = ["sailfish-macros/config"]
# automatically import derive macro
derive = ["sailfish-macros"]
extended_support = ["uuid", "chrono"]
# enable json filter
json = ["serde", "serde_json"]
# add more #[inline] attribute
Expand All @@ -26,6 +27,8 @@ perf-inline = []
[dependencies]
itoap = "1.0.1"
ryu = "1.0.13"
uuid = { version = "1.4.1", features = ["v4", "v8", "serde"], optional = true }
chrono = { version = "0.4.26", features = ["serde"], optional = true}
serde = { version = "1.0.159", optional = true }
serde_json = { version = "1.0.95", optional = true }

Expand Down
30 changes: 30 additions & 0 deletions sailfish/src/runtime/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ impl Render for char {
}
}

#[cfg(feature="extended_support")]
impl Render for uuid::Uuid {
#[inline]
fn render(&self, b: &mut Buffer) -> Result<(), RenderError> {
b.push_str(&self.to_string());
Ok(())
}

#[inline]
fn render_escaped(&self, b: &mut Buffer) -> Result<(), RenderError> {
escape::escape_to_buf(&self.to_string(), b);
Ok(())
}
}

#[cfg(feature="extended_support")]
impl Render for chrono::NaiveDateTime {
#[inline]
fn render(&self, b: &mut Buffer) -> Result<(), RenderError> {
b.push_str(&self.to_string());
Ok(())
}

#[inline]
fn render_escaped(&self, b: &mut Buffer) -> Result<(), RenderError> {
escape::escape_to_buf(&self.to_string(), b);
Ok(())
}
}

impl Render for PathBuf {
#[inline]
fn render(&self, b: &mut Buffer) -> Result<(), RenderError> {
Expand Down

0 comments on commit 0b38e26

Please sign in to comment.