Skip to content

Commit be6b782

Browse files
committed
Cargo fmt
1 parent 98d2bf2 commit be6b782

File tree

5 files changed

+42
-63
lines changed

5 files changed

+42
-63
lines changed

native/sorted_set_nif/src/bucket.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ impl Bucket {
3535
self.data.set_len(at);
3636
other.set_len(other_len);
3737

38-
ptr::copy_nonoverlapping(
39-
self.data.as_ptr().add(at),
40-
other.as_mut_ptr(),
41-
other.len(),
42-
);
38+
ptr::copy_nonoverlapping(self.data.as_ptr().add(at), other.as_mut_ptr(), other.len());
4339
}
4440

4541
Bucket { data: other }

native/sorted_set_nif/src/configuration.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ impl Default for Configuration {
2424
impl Configuration {
2525
pub fn new(max_bucket_size: usize, initial_set_capacity: usize) -> Self {
2626
Self {
27-
max_bucket_size: NonZeroUsize::new(max_bucket_size).expect("max_bucket_size must be greater than 0"),
28-
initial_set_capacity
27+
max_bucket_size: NonZeroUsize::new(max_bucket_size)
28+
.expect("max_bucket_size must be greater than 0"),
29+
initial_set_capacity,
2930
}
3031
}
3132

native/sorted_set_nif/src/lib.rs

+21-39
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use sorted_set::SortedSet;
1818
use std::sync::Mutex;
1919
use supported_term::SupportedTerm;
2020

21-
22-
2321
mod atoms {
2422
rustler_atoms! {
2523
// Common Atoms
@@ -54,7 +52,7 @@ pub enum Error {
5452
#[fail(display = "Not found")]
5553
NotFound,
5654
#[fail(display = "Max bucket size exceeded")]
57-
MaxBucketSizeExceeded
55+
MaxBucketSizeExceeded,
5856
}
5957

6058
pub struct FoundData {
@@ -63,7 +61,6 @@ pub struct FoundData {
6361
idx: usize,
6462
}
6563

66-
6764
rustler_export_nifs! {
6865
"Elixir.Discord.SortedSet.NifBridge",
6966
[
@@ -93,10 +90,7 @@ fn empty<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
9390

9491
let initial_set_capacity: usize = (initial_item_capacity / max_bucket_size) + 1;
9592

96-
let configuration = Configuration::new(
97-
max_bucket_size,
98-
initial_set_capacity,
99-
);
93+
let configuration = Configuration::new(max_bucket_size, initial_set_capacity);
10094

10195
let resource = ResourceArc::new(SortedSetResource(Mutex::new(SortedSet::empty(
10296
configuration,
@@ -111,10 +105,7 @@ fn new<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
111105

112106
let initial_set_capacity: usize = (initial_item_capacity / max_bucket_size) + 1;
113107

114-
let configuration = Configuration::new(
115-
max_bucket_size,
116-
initial_set_capacity,
117-
);
108+
let configuration = Configuration::new(max_bucket_size, initial_set_capacity);
118109

119110
let resource = ResourceArc::new(SortedSetResource(Mutex::new(SortedSet::new(configuration))));
120111

@@ -139,12 +130,12 @@ fn append_bucket<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
139130

140131
match set.append_bucket(items) {
141132
Ok(_) => Ok(atoms::ok().encode(env)),
142-
Err(e) => {
143-
match e {
144-
Error::MaxBucketSizeExceeded => Ok((atoms::error(), atoms::max_bucket_size_exceeded()).encode(env)),
145-
_ => unreachable!(),
133+
Err(e) => match e {
134+
Error::MaxBucketSizeExceeded => {
135+
Ok((atoms::error(), atoms::max_bucket_size_exceeded()).encode(env))
146136
}
147-
}
137+
_ => unreachable!(),
138+
},
148139
}
149140
}
150141

@@ -166,12 +157,10 @@ fn add<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
166157

167158
match set.add(item) {
168159
Ok(idx) => Ok((atoms::ok(), atoms::added(), idx).encode(env)),
169-
Err(e) => {
170-
match e {
171-
Error::Duplicate(idx) => Ok((atoms::ok(), atoms::duplicate(), idx).encode(env)),
172-
_ => unreachable!(),
173-
}
174-
}
160+
Err(e) => match e {
161+
Error::Duplicate(idx) => Ok((atoms::ok(), atoms::duplicate(), idx).encode(env)),
162+
_ => unreachable!(),
163+
},
175164
}
176165
}
177166

@@ -193,12 +182,10 @@ fn remove<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
193182

194183
match set.remove(&item) {
195184
Ok(idx) => Ok((atoms::ok(), atoms::removed(), idx).encode(env)),
196-
Err(e) => {
197-
match e {
198-
Error::NotFound => Ok((atoms::error(), atoms::not_found()).encode(env)),
199-
_ => unreachable!(),
200-
}
201-
}
185+
Err(e) => match e {
186+
Error::NotFound => Ok((atoms::error(), atoms::not_found()).encode(env)),
187+
_ => unreachable!(),
188+
},
202189
}
203190
}
204191

@@ -282,16 +269,11 @@ fn find_index<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
282269
};
283270

284271
match set.find_index(&item) {
285-
Ok(FoundData {
286-
idx,
287-
..
288-
}) => Ok((atoms::ok(), idx).encode(env)),
289-
Err(e) => {
290-
match e {
291-
Error::NotFound => Ok((atoms::error(), atoms::not_found()).encode(env)),
292-
_ => unreachable!(),
293-
}
294-
}
272+
Ok(FoundData { idx, .. }) => Ok((atoms::ok(), idx).encode(env)),
273+
Err(e) => match e {
274+
Error::NotFound => Ok((atoms::error(), atoms::not_found()).encode(env)),
275+
_ => unreachable!(),
276+
},
295277
}
296278
}
297279

native/sorted_set_nif/src/sorted_set.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ impl SortedSet {
5454
let bucket_idx = self.find_bucket_index(item);
5555

5656
match self.buckets[bucket_idx].data.binary_search(&item) {
57-
Ok(idx) => {
58-
Ok(FoundData {
59-
bucket_idx,
60-
inner_idx: idx,
61-
idx: self.effective_index(bucket_idx, idx),
62-
})
63-
}
57+
Ok(idx) => Ok(FoundData {
58+
bucket_idx,
59+
inner_idx: idx,
60+
idx: self.effective_index(bucket_idx, idx),
61+
}),
6462
Err(_) => Err(Error::NotFound),
6563
}
6664
}
@@ -93,12 +91,12 @@ impl SortedSet {
9391

9492
Ok(effective_idx)
9593
}
96-
Err(error) => {
97-
match error {
98-
Error::Duplicate(idx) => Err(Error::Duplicate(self.effective_index(bucket_idx, idx))),
99-
_ => unreachable!(),
94+
Err(error) => match error {
95+
Error::Duplicate(idx) => {
96+
Err(Error::Duplicate(self.effective_index(bucket_idx, idx)))
10097
}
101-
}
98+
_ => unreachable!(),
99+
},
102100
}
103101
}
104102

@@ -223,7 +221,6 @@ impl SortedSet {
223221
pub fn size(&self) -> usize {
224222
self.size
225223
}
226-
227224
}
228225

229226
impl Default for SortedSet {
@@ -237,8 +234,8 @@ mod tests {
237234
use configuration::Configuration;
238235
use supported_term::SupportedTerm;
239236
use supported_term::SupportedTerm::{Bitstring, Integer};
240-
use SortedSet;
241237
use Error;
238+
use SortedSet;
242239

243240
#[test]
244241
fn test_sorted() {
@@ -266,7 +263,10 @@ mod tests {
266263
assert_eq!(set.size(), 1);
267264

268265
let item = Bitstring(String::from("test-item"));
269-
assert!(set.add(item).map_err(|err| assert_eq!(err, Error::Duplicate(0))).is_err());
266+
assert!(set
267+
.add(item)
268+
.map_err(|err| assert_eq!(err, Error::Duplicate(0)))
269+
.is_err());
270270
assert_eq!(set.size(), 1);
271271
}
272272

native/sorted_set_nif/src/supported_term.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Ord for SupportedTerm {
5151
if self_length == other_length {
5252
for (self_term, term) in self_inner.iter().zip(inner.iter()) {
5353
match self_term.cmp(term) {
54-
Ordering::Equal => {},
54+
Ordering::Equal => {}
5555
o => return o,
5656
}
5757
}
@@ -99,4 +99,4 @@ impl Encoder for SupportedTerm {
9999
SupportedTerm::Bitstring(inner) => inner.encode(env),
100100
}
101101
}
102-
}
102+
}

0 commit comments

Comments
 (0)