Skip to content

Commit

Permalink
chore: bump version to 0.2.25
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu committed Dec 5, 2024
1 parent e9e882c commit 62ade0a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
20 changes: 18 additions & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faststr"
version = "0.2.24"
version = "0.2.25"
authors = ["Volo Team <[email protected]>"]
edition = "2021"
description = "Faststr is a string library that reduces the cost of clone."
Expand All @@ -18,6 +18,7 @@ simdutf8 = { version = "0.1", default-features = false, features = [
"aarch64_neon",
] }
redis = { version = "0.27", optional = true, default-features = false }
redis-0-26 = { version = "0.26", optional = true, default-features = false, package = "redis" }
itoa = { version = "1", optional = true }
ryu = { version = "1", optional = true }
rkyv = { version = "0.8", optional = true, default-features = false }
Expand All @@ -27,7 +28,7 @@ default = ["std"]
std = ["bytes/std", "simdutf8/std", "serde?/std", "rkyv?/std"]
serde = ["serde/alloc"]
serde-unsafe = ["serde"]
redis = ["std", "dep:redis", "itoa", "ryu"]
redis = ["std", "dep:redis", "itoa", "ryu", "dep:redis-0-26"]
redis-unsafe = ["redis"]
rkyv = ["rkyv/alloc"]

Expand Down
63 changes: 63 additions & 0 deletions src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,66 @@ impl redis::FromRedisValue for crate::FastStr {
}
}
}

mod compat_0_26 {
use redis_0_26 as redis;
impl redis::ToRedisArgs for crate::FastStr {
fn write_redis_args<W>(&self, out: &mut W)
where
W: ?Sized + redis::RedisWrite,
{
out.write_arg(self.as_bytes())
}
}

impl redis::FromRedisValue for crate::FastStr {
fn from_redis_value(v: &redis::Value) -> redis::RedisResult<Self> {
match v {
redis::Value::Nil => Ok(Self::empty()),
redis::Value::Int(v) => Ok(Self::new(itoa::Buffer::new().format(*v))),
redis::Value::Okay => Ok(Self::from_static_str("OK")),
#[cfg(feature = "redis-unsafe")]
redis::Value::BulkString(v) => {
Ok(unsafe { Self::new(std::str::from_utf8_unchecked(v)) })
}
#[cfg(not(feature = "redis-unsafe"))]
redis::Value::BulkString(v) => Ok(Self::new(std::str::from_utf8(v)?)),
redis::Value::SimpleString(v) => Ok(Self::new(v)),
redis::Value::Double(v) => Ok(Self::new(ryu::Buffer::new().format(*v))),
redis::Value::Boolean(v) => {
Ok(Self::from_static_str(if *v { "true" } else { "false" }))
}
redis::Value::BigNumber(v) => Ok(Self::from_string(v.to_string())),
e => Err(redis::RedisError::from((
redis::ErrorKind::TypeError,
"Invalid response type",
format!("{:?}", e),
))),
}
}

fn from_owned_redis_value(v: redis::Value) -> redis::RedisResult<Self> {
match v {
#[cfg(feature = "redis-unsafe")]
redis::Value::BulkString(v) => Ok(unsafe { Self::from_vec_u8_unchecked(v) }),
#[cfg(not(feature = "redis-unsafe"))]
redis::Value::BulkString(v) => Self::from_vec_u8(v)
.map_err(|_| (redis::ErrorKind::TypeError, "Invalid UTF8").into()),
redis::Value::Nil => Ok(Self::empty()),
redis::Value::Int(v) => Ok(Self::new(itoa::Buffer::new().format(v))),
redis::Value::Okay => Ok(Self::from_static_str("OK")),
redis::Value::SimpleString(v) => Ok(Self::from_string(v)),
redis::Value::Double(v) => Ok(Self::new(ryu::Buffer::new().format(v))),
redis::Value::Boolean(v) => {
Ok(Self::from_static_str(if v { "true" } else { "false" }))
}
redis::Value::BigNumber(v) => Ok(Self::from_string(v.to_string())),
e => Err(redis::RedisError::from((
redis::ErrorKind::TypeError,
"Invalid response type",
format!("{:?}", e),
))),
}
}
}
}

0 comments on commit 62ade0a

Please sign in to comment.