Enable fixed len mutable params in `action!` macro

next
Sayan Nandan 3 years ago
parent 589ef85e2c
commit b2c0b9ecf2

@ -33,8 +33,7 @@ use bytes::Bytes;
action!(
/// Run a `GET` query
fn get(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn get(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
err_if_len_is!(act, con, not 1);
let res: Option<Bytes> = {
let reader = handle.get_ref();

@ -30,8 +30,7 @@ action!(
/// Run a `KEYLEN` query
///
/// At this moment, `keylen` only supports a single key
fn keylen(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn keylen(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
err_if_len_is!(act, con, not 1);
let res: Option<usize> = {
let reader = handle.get_ref();

@ -30,8 +30,7 @@ use bytes::Bytes;
action!(
/// Run an `LSKEYS` query
fn lskeys(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn lskeys(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
err_if_len_is!(act, con, gt 1);
let item_count = if let Some(cnt) = act.next() {
if let Ok(cnt) = cnt.parse::<usize>() {

@ -29,8 +29,7 @@ use crate::dbnet::connection::prelude::*;
action!(
/// Run an `MSET` query
fn mset(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn mset(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
let howmany = act.len();
if is_lowbit_set!(howmany) || howmany == 0 {
// An odd number of arguments means that the number of keys

@ -29,8 +29,7 @@ use crate::dbnet::connection::prelude::*;
action!(
/// Run an `MUPDATE` query
fn mupdate(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn mupdate(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
let howmany = act.len();
if is_lowbit_set!(howmany) || howmany == 0 {
// An odd number of arguments means that the number of keys

@ -35,8 +35,7 @@ use coredb::Data;
action!(
/// Run a `SET` query
fn set(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn set(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
err_if_len_is!(act, con, not 2);
let did_we = {
if handle.is_poisoned() {

@ -44,8 +44,7 @@ action!(
///
/// This either returns `Okay` if all the keys were set, or it returns an
/// `Overwrite Error` or code `2`
fn sset(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn sset(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
let howmany = act.len();
if is_lowbit_set!(howmany) || howmany == 0 {
return con.write_response(responses::groups::ACTION_ERR).await;
@ -150,8 +149,7 @@ action!(
///
/// This either returns `Okay` if all the keys were updated, or it returns `Nil`
/// or code `1`
fn supdate(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn supdate(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
let howmany = act.len();
if is_lowbit_set!(howmany) || howmany == 0 {
return con.write_response(responses::groups::ACTION_ERR).await;

@ -33,8 +33,7 @@ use crate::dbnet::connection::prelude::*;
action!(
/// Run an `UPDATE` query
fn update(handle: &CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn update(handle: &CoreDB, con: &mut T, mut act: ActionIter) {
err_if_len_is!(act, con, not 2);
let did_we = {
if handle.is_poisoned() {

@ -33,8 +33,7 @@ action!(
/// Run an `USET` query
///
/// This is like "INSERT or UPDATE"
fn uset(handle: &crate::coredb::CoreDB, con: &mut T, act: ActionIter) {
let mut act = act;
fn uset(handle: &crate::coredb::CoreDB, con: &mut T, mut act: ActionIter) {
let howmany = act.len();
if is_lowbit_set!(howmany) || howmany == 0 {
// An odd number of arguments means that the number of keys

@ -63,6 +63,7 @@ const PAIR_MAP_LUT: [u8; 200] = [
0x39, 0x38, 0x39, 0x39, // 0x39
];
#[allow(dead_code)]
/// A 32-bit integer buffer with one extra byte
pub type Integer32Buffer = Integer32BufferRaw<11>;
@ -74,6 +75,7 @@ pub struct Integer32BufferRaw<const N: usize> {
inner_stack: Array<u8, 11>,
}
#[allow(dead_code)]
impl<const N: usize> Integer32BufferRaw<N> {
/// Initialize a buffer
pub fn init(integer: u32) -> Self {

@ -134,7 +134,7 @@ macro_rules! assert_hmeq {
///
/// ## Limitations
///
/// This macro cannot currently handle mutable parameters
/// This macro can only handle mutable parameters for a fixed number of arguments (three)
///
macro_rules! action {
(
@ -149,4 +149,16 @@ macro_rules! action {
Strm: AsyncReadExt + AsyncWriteExt + Unpin + Send + Sync,
$block
};
(
$(#[$attr:meta])*
fn $fname:ident($argone:ident: $argonety:ty, $argtwo:ident: $argtwoty:ty, mut $argthree:ident: $argthreety:ty)
$block:block
) => {
$(#[$attr])*
pub async fn $fname<T, Strm>($argone: $argonety, $argtwo: $argtwoty, mut $argthree: $argthreety) -> std::io::Result<()>
where
T: ProtocolConnectionExt<Strm>,
Strm: AsyncReadExt + AsyncWriteExt + Unpin + Send + Sync,
$block
};
}

Loading…
Cancel
Save