Skip to content

Commit b358a31

Browse files
committed
Format with cargo fmt
1 parent b8d50d3 commit b358a31

File tree

13 files changed

+148
-175
lines changed

13 files changed

+148
-175
lines changed

build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
extern crate cc;
21
extern crate bindgen;
2+
extern crate cc;
33

44
//use std::env;
55
//use std::path::PathBuf;
@@ -24,4 +24,4 @@ fn main() {
2424
bindings
2525
.write_to_file("src/redisraw/bindings.rs")
2626
.expect("failed to write bindings to file");
27-
}
27+
}

examples/data_type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[macro_use]
22
extern crate redismodule;
33

4-
use redismodule::{Context, RedisResult, NextArg};
54
use redismodule::native_types::RedisType;
5+
use redismodule::{Context, NextArg, RedisResult};
66

77
#[derive(Debug)]
88
struct MyType {
@@ -26,7 +26,7 @@ fn alloc_set(ctx: &Context, args: Vec<String>) -> RedisResult {
2626
}
2727
None => {
2828
let value = MyType {
29-
data: "A".repeat(size as usize)
29+
data: "A".repeat(size as usize),
3030
};
3131

3232
key.set_value(&MY_REDIS_TYPE, value)?;
@@ -48,7 +48,7 @@ fn alloc_get(ctx: &Context, args: Vec<String>) -> RedisResult {
4848
let _ = value;
4949
"some value".into()
5050
}
51-
None => ().into()
51+
None => ().into(),
5252
};
5353

5454
Ok(value)

examples/hello.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[macro_use]
22
extern crate redismodule;
33

4-
use redismodule::{Context, RedisResult, RedisError, parse_integer};
4+
use redismodule::{parse_integer, Context, RedisError, RedisResult};
55

66
fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
77
if args.len() < 2 {
@@ -24,7 +24,7 @@ fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
2424

2525
//////////////////////////////////////////////////////
2626

27-
redis_module!{
27+
redis_module! {
2828
name: "hello",
2929
version: 1,
3030
data_types: [],
@@ -42,10 +42,7 @@ mod tests {
4242
fn run_hello_mul(args: &[&str]) -> RedisResult {
4343
hello_mul(
4444
&Context::dummy(),
45-
args
46-
.iter()
47-
.map(|v| String::from(*v))
48-
.collect(),
45+
args.iter().map(|v| String::from(*v)).collect(),
4946
)
5047
}
5148

@@ -55,12 +52,15 @@ mod tests {
5552

5653
match result {
5754
Ok(RedisValue::Array(v)) => {
58-
assert_eq!(v, vec![10, 20, 30, 6000]
59-
.into_iter()
60-
.map(RedisValue::Integer)
61-
.collect::<Vec<_>>());
55+
assert_eq!(
56+
v,
57+
vec![10, 20, 30, 6000]
58+
.into_iter()
59+
.map(RedisValue::Integer)
60+
.collect::<Vec<_>>()
61+
);
6262
}
63-
_ => assert!(false, "Bad result: {:?}", result)
63+
_ => assert!(false, "Bad result: {:?}", result),
6464
}
6565
}
6666

@@ -72,8 +72,7 @@ mod tests {
7272
Err(RedisError::String(s)) => {
7373
assert_eq!(s, "Couldn't parse as integer: xx");
7474
}
75-
_ => assert!(false, "Bad result: {:?}", result)
75+
_ => assert!(false, "Bad result: {:?}", result),
7676
}
7777
}
7878
}
79-

src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use std::alloc::{GlobalAlloc, Layout, System};
12
use std::os::raw::c_void;
2-
use std::alloc::{System, GlobalAlloc, Layout};
3-
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering::SeqCst};
3+
use std::sync::atomic::{AtomicBool, Ordering::SeqCst, ATOMIC_BOOL_INIT};
44

55
use crate::raw;
66

src/context.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::ptr;
2-
use std::os::raw::c_long;
31
use std::ffi::CString;
2+
use std::os::raw::c_long;
3+
use std::ptr;
44

5+
use crate::key::{RedisKey, RedisKeyWritable};
56
use crate::raw;
67
use crate::LogLevel;
7-
use crate::key::{RedisKey, RedisKeyWritable};
8-
use crate::{RedisString, RedisError, RedisValue, RedisResult};
8+
use crate::{RedisError, RedisResult, RedisString, RedisValue};
99

1010
/// Redis is a structure that's designed to give us a high-level interface to
1111
/// the Redis module API by abstracting away the raw C FFI calls.
@@ -19,7 +19,9 @@ impl Context {
1919
}
2020

2121
pub fn dummy() -> Self {
22-
Self { ctx: ptr::null_mut() }
22+
Self {
23+
ctx: ptr::null_mut(),
24+
}
2325
}
2426

2527
pub fn log(&self, level: LogLevel, message: &str) {
@@ -33,7 +35,8 @@ impl Context {
3335
}
3436

3537
pub fn call(&self, command: &str, args: &[&str]) -> RedisResult {
36-
let terminated_args: Vec<RedisString> = args.iter()
38+
let terminated_args: Vec<RedisString> = args
39+
.iter()
3740
.map(|s| RedisString::create(self.ctx, s))
3841
.collect();
3942

@@ -48,13 +51,15 @@ impl Context {
4851
match r {
4952
Ok(RedisValue::Integer(v)) => unsafe {
5053
raw::RedisModule_ReplyWithLongLong.unwrap()(self.ctx, v).into()
51-
}
54+
},
5255

5356
Ok(RedisValue::String(s)) => unsafe {
5457
raw::RedisModule_ReplyWithString.unwrap()(
5558
self.ctx,
56-
RedisString::create(self.ctx, s.as_ref()).inner).into()
57-
}
59+
RedisString::create(self.ctx, s.as_ref()).inner,
60+
)
61+
.into()
62+
},
5863

5964
Ok(RedisValue::Array(array)) => {
6065
unsafe {
@@ -72,21 +77,21 @@ impl Context {
7277

7378
Ok(RedisValue::None) => unsafe {
7479
raw::RedisModule_ReplyWithNull.unwrap()(self.ctx).into()
75-
}
80+
},
7681

7782
Err(RedisError::WrongArity) => unsafe {
7883
raw::RedisModule_WrongArity.unwrap()(self.ctx).into()
79-
}
84+
},
8085

8186
Err(RedisError::String(s)) => unsafe {
8287
let msg = CString::new(s).unwrap();
8388
raw::RedisModule_ReplyWithError.unwrap()(self.ctx, msg.as_ptr()).into()
84-
}
89+
},
8590

8691
Err(RedisError::Str(s)) => unsafe {
8792
let msg = CString::new(s).unwrap();
8893
raw::RedisModule_ReplyWithError.unwrap()(self.ctx, msg.as_ptr()).into()
89-
}
94+
},
9095
}
9196
}
9297

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std;
22
use std::error;
33
use std::fmt;
4-
use std::fmt::{Display};
4+
use std::fmt::Display;
55

66
#[derive(Debug)]
77
pub enum Error {

src/key.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
use std::fmt::Debug;
2+
use std::os::raw::c_void;
13
use std::ptr;
24
use std::string;
3-
use std::os::raw::c_void;
4-
use std::fmt::Debug;
55

66
use libc::size_t;
77

8-
use crate::raw;
98
use crate::error::Error;
10-
use crate::RedisString;
11-
use crate::native_types::RedisType;
129
use crate::from_byte_string;
13-
use crate::RedisResult;
14-
use crate::RedisError;
1510
use crate::native_types::redis_log;
11+
use crate::native_types::RedisType;
12+
use crate::raw;
13+
use crate::RedisError;
14+
use crate::RedisResult;
15+
use crate::RedisString;
1616

1717
/// `RedisKey` is an abstraction over a Redis key that allows readonly
1818
/// operations.
@@ -86,8 +86,7 @@ pub struct RedisKeyWritable {
8686
impl RedisKeyWritable {
8787
pub fn open(ctx: *mut raw::RedisModuleCtx, key: &str) -> RedisKeyWritable {
8888
let key_str = RedisString::create(ctx, key);
89-
let key_inner =
90-
raw::open_key(ctx, key_str.inner, to_raw_mode(KeyMode::ReadWrite));
89+
let key_inner = raw::open_key(ctx, key_str.inner, to_raw_mode(KeyMode::ReadWrite));
9190
RedisKeyWritable {
9291
ctx,
9392
key_inner,
@@ -138,31 +137,26 @@ impl RedisKeyWritable {
138137
pub fn is_empty(&self) -> bool {
139138
use raw::KeyType;
140139

141-
let key_type: KeyType = unsafe {
142-
raw::RedisModule_KeyType.unwrap()(self.key_inner)
143-
}.into();
140+
let key_type: KeyType = unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into();
144141

145142
key_type == KeyType::Empty
146143
}
147144

148145
fn verify_type(&self, redis_type: &RedisType) -> RedisResult {
149146
use raw::KeyType;
150147

151-
let key_type: KeyType = unsafe {
152-
raw::RedisModule_KeyType.unwrap()(self.key_inner)
153-
}.into();
148+
let key_type: KeyType = unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into();
154149

155150
redis_log(self.ctx, format!("key type: {:?}", key_type).as_str());
156151

157152
if key_type != KeyType::Empty {
158153
// The key exists; check its type
159-
let raw_type = unsafe {
160-
raw::RedisModule_ModuleTypeGetType.unwrap()(self.key_inner)
161-
};
154+
let raw_type = unsafe { raw::RedisModule_ModuleTypeGetType.unwrap()(self.key_inner) };
162155

163156
if raw_type != *redis_type.raw_type.borrow() {
164157
return Err(RedisError::String(format!(
165-
"Existing key has wrong Redis type")));
158+
"Existing key has wrong Redis type"
159+
)));
166160
}
167161

168162
redis_log(self.ctx, "Existing key is of the correct type");
@@ -173,17 +167,19 @@ impl RedisKeyWritable {
173167
Ok("OK".into())
174168
}
175169

176-
pub fn get_value<T: Debug>(&self, redis_type: &RedisType) -> Result<Option<&mut T>, RedisError> {
170+
pub fn get_value<T: Debug>(
171+
&self,
172+
redis_type: &RedisType,
173+
) -> Result<Option<&mut T>, RedisError> {
177174
self.verify_type(redis_type)?;
178175

179176
redis_log(self.ctx, "Going to get value");
180177

181-
let value = unsafe {
182-
raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner) as *mut T
183-
};
178+
let value =
179+
unsafe { raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner) as *mut T };
184180

185181
if value.is_null() {
186-
return Ok(None)
182+
return Ok(None);
187183
}
188184

189185
let value = unsafe { &mut *value };
@@ -196,7 +192,10 @@ impl RedisKeyWritable {
196192
pub fn set_value<T: Debug>(&self, redis_type: &RedisType, value: T) -> Result<(), RedisError> {
197193
self.verify_type(redis_type)?;
198194

199-
redis_log(self.ctx, format!("1. Going to set value to {:?}", &value).as_str());
195+
redis_log(
196+
self.ctx,
197+
format!("1. Going to set value to {:?}", &value).as_str(),
198+
);
200199

201200
let value = Box::into_raw(Box::new(value)) as *mut c_void;
202201

@@ -208,7 +207,8 @@ impl RedisKeyWritable {
208207
*redis_type.raw_type.borrow(),
209208
value,
210209
)
211-
}.into();
210+
}
211+
.into();
212212

213213
redis_log(self.ctx, "3. Finished setting value");
214214

@@ -225,7 +225,6 @@ impl From<raw::Status> for Result<(), RedisError> {
225225
}
226226
}
227227

228-
229228
impl Drop for RedisKeyWritable {
230229
// Frees resources appropriately as a RedisKey goes out of scope.
231230
fn drop(&mut self) {

src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//#![allow(dead_code)]
22

3-
use std::string;
43
use std::os::raw::c_char;
4+
use std::string;
55

66
#[macro_use]
77
extern crate bitflags;
@@ -11,12 +11,12 @@ extern crate num_traits;
1111

1212
use libc::size_t;
1313

14-
pub mod redismodule;
1514
pub mod alloc;
16-
pub mod redisraw;
1715
pub mod error;
18-
pub mod raw;
1916
pub mod native_types;
17+
pub mod raw;
18+
pub mod redismodule;
19+
pub mod redisraw;
2020

2121
#[macro_use]
2222
mod macros;
@@ -29,7 +29,6 @@ pub use redismodule::*;
2929
#[global_allocator]
3030
static ALLOC: crate::alloc::RedisAlloc = crate::alloc::RedisAlloc;
3131

32-
3332
/// `LogLevel` is a level of logging to be specified with a Redis log directive.
3433
#[derive(Clone, Copy, Debug)]
3534
pub enum LogLevel {
@@ -51,7 +50,6 @@ pub enum Reply {
5150
Unknown,
5251
}
5352

54-
5553
fn from_byte_string(
5654
byte_str: *const c_char,
5755
length: size_t,
@@ -64,4 +62,3 @@ fn from_byte_string(
6462

6563
String::from_utf8(vec_str)
6664
}
67-

0 commit comments

Comments
 (0)