3434//! ```
3535//!
3636
37- use crate :: error:: { errorstring, SkyhashError } ;
38- use crate :: types:: { Array , FlatElement } ;
39- use crate :: Element ;
40- use crate :: IntoSkyhashBytes ;
41- use crate :: Query ;
42- use crate :: RespCode ;
43- use crate :: SkyResult ;
37+ use crate :: {
38+ error:: { errorstring, SkyhashError } ,
39+ types:: Array ,
40+ Element , IntoSkyhashBytes , Query , RespCode , SkyResult ,
41+ } ;
4442
4543cfg_async ! {
4644 use crate :: AsyncResult ;
@@ -64,6 +62,7 @@ pub enum KeymapType {
6462}
6563
6664/// A convenient representation for the `whereami` action
65+ #[ derive( Debug , PartialEq ) ]
6766pub enum WhereAmI {
6867 /// The ID of the keyspace
6968 Keyspace ( String ) ,
@@ -283,29 +282,13 @@ implement_ddl! {
283282 {
284283 Query :: from( "whereami" )
285284 }
286- Element :: Array (
287- Array :: Flat ( mut frr)
288- ) => {
289- if frr. iter( ) . all( |v| matches!( v, FlatElement :: String ( _) ) ) {
290- return Err ( SkyhashError :: InvalidResponse . into( ) ) ;
291- }
292- match frr. len( ) {
293- 1 => WhereAmI :: Keyspace ( match frr. swap_remove( 0 ) {
294- FlatElement :: String ( st) => st,
295- _ => unsafe {
296- core:: hint:: unreachable_unchecked( )
297- }
298- } ) ,
299- 2 => {
300- let ( ks, tbl) = match ( frr. swap_remove( 0 ) , frr. swap_remove( 1 ) ) {
301- ( FlatElement :: String ( ks) , FlatElement :: String ( tbl) ) => ( ks, tbl) ,
302- _ => unsafe {
303- core:: hint:: unreachable_unchecked( )
304- }
305- } ;
306- WhereAmI :: Table ( ks, tbl)
285+ Element :: Array ( Array :: NonNullStr ( mut a) ) => {
286+ unsafe {
287+ match a. len( ) {
288+ 1 => WhereAmI :: Keyspace ( a. pop( ) . unwrap_unchecked( ) ) ,
289+ 2 => WhereAmI :: Table ( a. pop( ) . unwrap_unchecked( ) , a. pop( ) . unwrap_unchecked( ) ) ,
290+ _ => return Err ( SkyhashError :: ParseError . into( ) ) ,
307291 }
308- _ => return Err ( SkyhashError :: InvalidResponse . into( ) ) ,
309292 }
310293 }
311294 }
0 commit comments