Skip to content

Commit 155bba6

Browse files
committed
fix: clippy
1 parent 204a083 commit 155bba6

File tree

19 files changed

+85
-57
lines changed

19 files changed

+85
-57
lines changed

src/action/ffi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use std::ptr::null;
1212
/// Returns null if an error happens, otherwise it returns a pointer to an action
1313
pub unsafe extern "C" fn redirectionio_action_json_deserialize(str: *mut c_char) -> *const Action {
1414
let action_str = match c_char_to_str(str) {
15-
None => return null() as *const Action,
15+
None => return null(),
1616
Some(str) => str,
1717
};
1818

1919
let action = match json_decode(action_str) {
2020
Err(error) => {
2121
error!("Unable to deserialize \"{}\" to action: {}", action_str, error,);
2222

23-
return null() as *const Action;
23+
return null();
2424
}
2525
Ok(action) => action,
2626
};
@@ -96,7 +96,7 @@ pub unsafe extern "C" fn redirectionio_action_body_filter_create(
9696
response_header_map: *const HeaderMap,
9797
) -> *const FilterBodyAction {
9898
if _action.is_null() {
99-
return null() as *const FilterBodyAction;
99+
return null();
100100
}
101101

102102
let action = &mut *_action;

src/api/ffi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ pub unsafe extern "C" fn redirectionio_api_get_rule_api_version() -> *const c_ch
1515
#[no_mangle]
1616
pub unsafe extern "C" fn redirectionio_api_create_rules_message_from_json(content: *mut c_char) -> *const RulesMessage {
1717
let message_string = match c_char_to_str(content) {
18-
None => return null() as *const RulesMessage,
18+
None => return null(),
1919
Some(str) => str,
2020
};
2121

2222
match json_decode(message_string) {
2323
Err(error) => {
2424
error!("{}", error);
25-
null() as *const RulesMessage
25+
null()
2626
}
2727
Ok(message) => Box::into_raw(Box::new(message)),
2828
}

src/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub unsafe extern "C" fn redirectionio_router_drop(_router: *mut Router<Rule>) {
8282
#[no_mangle]
8383
pub unsafe extern "C" fn redirectionio_router_match_action(_router: *const Router<Rule>, _request: *const Request) -> *const Action {
8484
if _router.is_null() || _request.is_null() {
85-
return null() as *const Action;
85+
return null();
8686
}
8787

8888
let router = &*_router;

src/http/ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct HeaderMap {
1515

1616
/// # Safety
1717
pub unsafe fn http_headers_to_header_map(headers: Vec<Header>) -> *const HeaderMap {
18-
let mut current: *const HeaderMap = null() as *const HeaderMap;
18+
let mut current: *const HeaderMap = null();
1919

2020
for header in &headers {
2121
current = Box::into_raw(Box::new(HeaderMap {
@@ -59,15 +59,15 @@ pub unsafe fn header_map_to_http_headers(header_map: *const HeaderMap) -> Vec<He
5959
/// # Safety
6060
pub unsafe extern "C" fn redirectionio_request_json_deserialize(str: *mut c_char) -> *const Request {
6161
let request_str = match c_char_to_str(str) {
62-
None => return null() as *const Request,
62+
None => return null(),
6363
Some(str) => str,
6464
};
6565

6666
let request = match json_decode(request_str) {
6767
Err(err) => {
6868
error!("cannot deserialize request {} for string {}", err, request_str);
6969

70-
return null() as *const Request;
70+
return null();
7171
}
7272
Ok(request) => request,
7373
};
@@ -201,7 +201,7 @@ pub unsafe extern "C" fn redirectionio_request_from_str(_url: *const c_char) ->
201201
Err(err) => {
202202
error!("cannot create request for url {}: {}", url, err);
203203

204-
null() as *const Request
204+
null()
205205
}
206206
Ok(request) => Box::into_raw(Box::new(request)),
207207
}

src/regex_radix_tree/item.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ impl<V> Item<V> {
7676
}
7777
}
7878

79+
pub fn is_empty(&self) -> bool {
80+
match self {
81+
Item::Empty(_) => true,
82+
Item::Node(node) => node.is_empty(),
83+
Item::Leaf(leaf) => leaf.is_empty(),
84+
}
85+
}
86+
7987
pub fn regex(&self) -> &str {
8088
match self {
8189
Item::Empty(_) => "",
@@ -96,7 +104,7 @@ impl<V> Item<V> {
96104
/// Implementation must retain at which level this node is build and not do any caching
97105
/// if we are not on the current level
98106
pub fn cache(&mut self, left: u64, cache_level: u64, current_level: u64) -> u64 {
99-
if left <= 0 {
107+
if left == 0 {
100108
return left;
101109
}
102110

src/regex_radix_tree/leaf.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ impl<V> Leaf<V> {
104104
self.values.len()
105105
}
106106

107+
pub fn is_empty(&self) -> bool {
108+
self.values.is_empty()
109+
}
110+
107111
pub fn regex(&self) -> &str {
108112
self.regex.original.as_str()
109113
}

src/regex_radix_tree/node.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<V> Node<V> {
124124
removed = value;
125125
}
126126

127-
if child.len() > 0 {
127+
if !child.is_empty() {
128128
children.push(child);
129129
}
130130
}
@@ -150,6 +150,16 @@ impl<V> Node<V> {
150150
count
151151
}
152152

153+
pub fn is_empty(&self) -> bool {
154+
for child in &self.children {
155+
if !child.is_empty() {
156+
return false;
157+
}
158+
}
159+
160+
true
161+
}
162+
153163
/// Cache current regex according to a limit and a level
154164
///
155165
/// This method must return new limit of element cached (passed limit minus number of element cached)
@@ -167,7 +177,7 @@ impl<V> Node<V> {
167177
self.regex.compile();
168178

169179
if self.regex.compiled.is_some() {
170-
left = left - 1;
180+
left -= 1;
171181
}
172182
}
173183

src/regex_radix_tree/prefix.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ macro_rules! next_char_or_return {
99

1010
pub fn common_prefix(left: &str, right: &str) -> String {
1111
let size = common_prefix_char_size(left, right);
12-
let prefix = get_prefix_with_char_size(left, size);
1312

14-
prefix
13+
get_prefix_with_char_size(left, size)
1514
}
1615

1716
pub fn common_prefix_char_size(left: &str, right: &str) -> u32 {

src/regex_radix_tree/regex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl LazyRegex {
4848
}
4949

5050
pub fn create_regex(&self) -> Option<Regex> {
51-
match RegexBuilder::new(&self.regex.as_str()).case_insensitive(self.ignore_case).build() {
51+
match RegexBuilder::new(self.regex.as_str()).case_insensitive(self.ignore_case).build() {
5252
Ok(regex) => Some(regex),
5353
Err(e) => {
5454
tracing::error!("cannot create regex: {:?}", e);

src/regex_radix_tree/trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<V> Leaf<V> {
2020
matched,
2121
count: self.values.len() as u64,
2222
children: Vec::new(),
23-
values: self.values.values().into_iter().collect(),
23+
values: self.values.values().collect(),
2424
}
2525
}
2626
}

0 commit comments

Comments
 (0)