Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add extended support, supports uuid and naivedatetime #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading