Skip to content

Commit

Permalink
Still use Part::Str for append, with 'static lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Sep 21, 2024
1 parent ff84801 commit 3c3e5fd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(crate) enum SqlBuilder {
pub(crate) enum Part {
Arg,
Fields,
Str(&'static str),
Text(String),
}

Expand Down Expand Up @@ -85,16 +86,12 @@ impl SqlBuilder {
}
}

pub(crate) fn append(&mut self, suffix: &str) {
pub(crate) fn append(&mut self, suffix: &'static str) {
let Self::InProgress(parts) = self else {
return;
};

if let Some(Part::Text(text)) = parts.last_mut() {
text.push_str(suffix);
} else {
parts.push(Part::Text(suffix.to_string()));
}
parts.push(Part::Str(suffix));
}

pub(crate) fn finish(mut self) -> Result<String> {
Expand All @@ -103,6 +100,7 @@ impl SqlBuilder {
if let Self::InProgress(parts) = &self {
for part in parts {
match part {
Part::Str(text) => sql.push_str(text),
Part::Text(text) => sql.push_str(text),
Part::Arg => {
self.error("unbound query argument");
Expand Down

0 comments on commit 3c3e5fd

Please sign in to comment.