Skip to content

Commit fb7c380

Browse files
committed
add two more From Option<String> to RedisValue
1 parent 48bdfb6 commit fb7c380

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/redismodule.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use core::num::{ParseFloatError, ParseIntError};
12
use std::ffi::CString;
23
use std::slice;
34
use std::str;
4-
use core::num::{ParseFloatError, ParseIntError};
55

66
pub type RedisResult = Result<RedisValue, RedisError>;
77

@@ -68,6 +68,21 @@ impl From<&str> for RedisValue {
6868
}
6969
}
7070

71+
impl From<Option<String>> for RedisValue {
72+
fn from(s: Option<String>) -> Self {
73+
match s {
74+
Some(v) => RedisValue::SimpleString(v),
75+
None => RedisValue::None,
76+
}
77+
}
78+
}
79+
80+
impl From<Vec<Option<String>>> for RedisValue {
81+
fn from(strings: Vec<Option<String>>) -> Self {
82+
RedisValue::Array(strings.into_iter().map(|v| v.into()).collect())
83+
}
84+
}
85+
7186
impl From<Vec<String>> for RedisValue {
7287
fn from(strings: Vec<String>) -> Self {
7388
RedisValue::Array(strings.into_iter().map(RedisValue::BulkString).collect())
@@ -76,7 +91,12 @@ impl From<Vec<String>> for RedisValue {
7691

7792
impl From<Vec<&String>> for RedisValue {
7893
fn from(strings: Vec<&String>) -> Self {
79-
RedisValue::Array(strings.into_iter().map(|s| RedisValue::BulkString(s.to_string())).collect())
94+
RedisValue::Array(
95+
strings
96+
.into_iter()
97+
.map(|s| RedisValue::BulkString(s.to_string()))
98+
.collect(),
99+
)
80100
}
81101
}
82102

0 commit comments

Comments
 (0)