Skip to content

Commit 3f3ae69

Browse files
authored
Add next_str to NextArg (#162)
* add next_str (cherry picked from commit 693ac9d)
1 parent 250e986 commit 3f3ae69

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/redismodule.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub const TYPE_METHOD_VERSION: u64 = raw::REDISMODULE_TYPE_METHOD_VERSION as u64
2121
pub trait NextArg {
2222
fn next_arg(&mut self) -> Result<RedisString, RedisError>;
2323
fn next_string(&mut self) -> Result<String, RedisError>;
24+
fn next_str<'a>(&mut self) -> Result<&'a str, RedisError>;
2425
fn next_i64(&mut self) -> Result<i64, RedisError>;
2526
fn next_u64(&mut self) -> Result<u64, RedisError>;
2627
fn next_f64(&mut self) -> Result<f64, RedisError>;
@@ -43,7 +44,13 @@ where
4344
}
4445

4546
#[inline]
46-
fn next_i64(&mut self) -> Result<i64, RedisError> {
47+
fn next_str<'a>(&mut self) -> Result<&'a str, RedisError> {
48+
self.next()
49+
.map_or(Err(RedisError::WrongArity), |v| v.try_as_str())
50+
}
51+
52+
#[inline]
53+
fn next_i64(&mut self) -> Result<i64, RedisError> {
4754
self.next()
4855
.map_or(Err(RedisError::WrongArity), |v| v.parse_integer())
4956
}
@@ -126,7 +133,7 @@ impl RedisString {
126133
len == 0
127134
}
128135

129-
pub fn try_as_str(&self) -> Result<&str, RedisError> {
136+
pub fn try_as_str<'a>(&self) -> Result<&'a str, RedisError> {
130137
Self::from_ptr(self.inner).map_err(|_| RedisError::Str("Couldn't parse as UTF-8 string"))
131138
}
132139

0 commit comments

Comments
 (0)