@@ -18,8 +18,6 @@ use sorted_set::SortedSet;
1818use std:: sync:: Mutex ;
1919use supported_term:: SupportedTerm ;
2020
21-
22-
2321mod 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
6058pub struct FoundData {
@@ -63,7 +61,6 @@ pub struct FoundData {
6361 idx : usize ,
6462}
6563
66-
6764rustler_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,10 @@ 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 ! ( ) ,
146- }
133+ Err ( Error :: MaxBucketSizeExceeded ) => {
134+ Ok ( ( atoms:: error ( ) , atoms:: max_bucket_size_exceeded ( ) ) . encode ( env) )
147135 }
136+ _ => unreachable ! ( ) ,
148137 }
149138}
150139
@@ -166,12 +155,8 @@ fn add<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
166155
167156 match set. add ( item) {
168157 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- }
158+ Err ( Error :: Duplicate ( idx) ) => Ok ( ( atoms:: ok ( ) , atoms:: duplicate ( ) , idx) . encode ( env) ) ,
159+ _ => unreachable ! ( ) ,
175160 }
176161}
177162
@@ -193,12 +178,8 @@ fn remove<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
193178
194179 match set. remove ( & item) {
195180 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- }
181+ Err ( Error :: NotFound ) => Ok ( ( atoms:: error ( ) , atoms:: not_found ( ) ) . encode ( env) ) ,
182+ _ => unreachable ! ( ) ,
202183 }
203184}
204185
@@ -282,16 +263,9 @@ fn find_index<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
282263 } ;
283264
284265 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- }
266+ Ok ( FoundData { idx, .. } ) => Ok ( ( atoms:: ok ( ) , idx) . encode ( env) ) ,
267+ Err ( Error :: NotFound ) => Ok ( ( atoms:: error ( ) , atoms:: not_found ( ) ) . encode ( env) ) ,
268+ _ => unreachable ! ( ) ,
295269 }
296270}
297271
0 commit comments