Skip to content

Commit

Permalink
Merge pull request #1257 from muzarski/cql-value-non-exhaustive
Browse files Browse the repository at this point in the history
value: mark CqlValue as non_exhaustive
  • Loading branch information
Lorak-mmk authored Feb 25, 2025
2 parents c24db77 + 7810380 commit 370506e
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 414 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock.msrv

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

5 changes: 3 additions & 2 deletions scylla-cql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ secrecy-08 = { package = "secrecy", version = "0.8", optional = true }
snap = "1.0"
uuid = "1.0"
thiserror = "2.0.6"
itertools = "0.14.0"
num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true }
num-bigint-04 = { package = "num-bigint", version = "0.4", optional = true }
bigdecimal-04 = { package = "bigdecimal", version = "0.4", optional = true }
chrono-04 = { package = "chrono", version = "0.4.32", default-features = false, optional = true }
chrono-04 = { package = "chrono", version = "0.4.32", default-features = false, features = ["alloc"] }
lz4_flex = { version = "0.11.1" }
async-trait = "0.1.57"
serde = { version = "1.0", features = ["derive"], optional = true }
Expand All @@ -45,7 +46,7 @@ harness = false
[features]
secrecy-08 = ["dep:secrecy-08"]
time-03 = ["dep:time-03"]
chrono-04 = ["dep:chrono-04"]
chrono-04 = []
num-bigint-03 = ["dep:num-bigint-03"]
num-bigint-04 = ["dep:num-bigint-04"]
bigdecimal-04 = ["dep:bigdecimal-04"]
Expand Down
2 changes: 2 additions & 0 deletions scylla-cql/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub(crate) mod pretty;

pub mod frame;
#[macro_use]
pub mod macros {
Expand Down
70 changes: 70 additions & 0 deletions scylla-cql/src/pretty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::fmt::{Display, LowerHex, UpperHex};

pub(crate) struct HexBytes<'a>(pub(crate) &'a [u8]);

impl LowerHex for HexBytes<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for b in self.0 {
write!(f, "{:02x}", b)?;
}
Ok(())
}
}

impl UpperHex for HexBytes<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for b in self.0 {
write!(f, "{:02X}", b)?;
}
Ok(())
}
}

pub(crate) struct CqlStringLiteralDisplayer<'a>(pub(crate) &'a str);

impl Display for CqlStringLiteralDisplayer<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// CQL string literals use single quotes. The only character that
// needs escaping is singular quote, and escaping is done by repeating
// the quote character.
f.write_str("'")?;
let mut first = true;
for part in self.0.split('\'') {
if first {
first = false;
} else {
f.write_str("''")?;
}
f.write_str(part)?;
}
f.write_str("'")?;
Ok(())
}
}

pub(crate) struct PairDisplayer<K, V>(pub(crate) K, pub(crate) V);

impl<K, V> Display for PairDisplayer<K, V>
where
K: Display,
V: Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.0, self.1)
}
}

pub(crate) struct MaybeNullDisplayer<T>(pub(crate) Option<T>);

impl<T> Display for MaybeNullDisplayer<T>
where
T: Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.0 {
None => write!(f, "null")?,
Some(v) => write!(f, "{}", v)?,
}
Ok(())
}
}
Loading

0 comments on commit 370506e

Please sign in to comment.