From 54e82f78d7601b5875628ade9ec325a8e7f4570f Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 23 Jul 2020 17:09:30 +0300 Subject: [PATCH] feat: add flush bucket and flush object commands BREAKING CHANGES: push, query and suggestion commands with optional variables now haven't option arguments in methods --- Cargo.toml | 8 ++++---- src/channel.rs | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa441c1..45da24e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sonic-channel" -version = "0.1.0" +version = "0.2.0" authors = ["Dmitriy Pleshevskiy "] description = "Rust client for sonic search backend" categories = ["api-bindings"] @@ -16,13 +16,13 @@ readme = "README.md" [dependencies] lazy_static = "1.4.0" -regex = "1.3.4" +regex = { version = "1.3.4", optional = true } [features] default = ["search"] -ingest = [] -search = [] +ingest = ["regex"] +search = ["regex"] control = [] diff --git a/src/channel.rs b/src/channel.rs index 0987e2a..04ab784 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -14,22 +14,27 @@ macro_rules! init_commands { $( use $cmd_name:ident for fn $fn_name:ident - $(<$($lt:lifetime)+>)? - ($($args:tt)*) - ; + $(<$($lt:lifetime)+>)? ( + $($args:tt)* + ); )* ) => { $(init_commands!(use $cmd_name for fn $fn_name $(<$($lt)+>)? ($($args)*));)* }; - (use $cmd_name:ident for fn $fn_name:ident $(<$($lt:lifetime)+>)? ($($arg_name:ident : $arg_type:ty,)*)) => { + ( + use $cmd_name:ident + for fn $fn_name:ident $(<$($lt:lifetime)+>)? ( + $($arg_name:ident : $arg_type:ty $( => $arg_value:expr)?,)* + ) + ) => { pub fn $fn_name $(<$($lt)+>)? ( &self, $($arg_name: $arg_type),* ) -> crate::result::Result< <$cmd_name as crate::commands::StreamCommand>::Response, > { - let command = $cmd_name { $($arg_name,)* ..Default::default() }; + let command = $cmd_name { $($arg_name $(: $arg_value)?,)* ..Default::default() }; self.run_command(command) } }; @@ -178,7 +183,7 @@ impl SonicChannel { bucket: &'a str, object: &'a str, text: &'a str, - locale: Option<&'a str>, + locale: &'a str => Some(locale), ); use FlushCommand for fn flushc<'a>( @@ -198,15 +203,15 @@ impl SonicChannel { collection: &'a str, bucket: &'a str, terms: &'a str, - limit: Option, + limit: usize => Some(limit), ); use QueryCommand for fn query_with_limit_and_offset<'a>( collection: &'a str, bucket: &'a str, terms: &'a str, - limit: Option, - offset: Option, + limit: usize => Some(limit), + offset: usize => Some(limit), ); use SuggestCommand for fn suggest<'a>( @@ -219,7 +224,7 @@ impl SonicChannel { collection: &'a str, bucket: &'a str, word: &'a str, - limit: Option, + limit: usize => Some(limit), ); }