use operations::cdt::{CdtArgument, CdtOpType, CdtOperation};
use operations::{Operation, OperationBin, OperationData, OperationType};
use Value;
pub fn append<'a>(bin: &'a str, value: &'a Value) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtOpType::ListAppend,
args: vec![CdtArgument::Value(value)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn append_items<'a>(bin: &'a str, values: &'a [Value]) -> Operation<'a> {
assert!(!values.is_empty());
let cdt_op = CdtOperation {
op: CdtOpType::ListAppendItems,
args: vec![CdtArgument::List(values)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn insert<'a>(bin: &'a str, index: i64, value: &'a Value) -> Operation<'a> {
let cdt_op = CdtOperation {
op: CdtOpType::ListInsert,
args: vec![CdtArgument::Int(index), CdtArgument::Value(value)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn insert_items<'a>(bin: &'a str, index: i64, values: &'a [Value]) -> Operation<'a> {
assert!(!values.is_empty());
let cdt_op = CdtOperation {
op: CdtOpType::ListInsertItems,
args: vec![CdtArgument::Int(index), CdtArgument::List(values)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn pop(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListPop,
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn pop_range(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListPopRange,
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn pop_range_from(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListPopRange,
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListRemove,
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove_range(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListRemoveRange,
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn remove_range_from(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListRemoveRange,
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn set<'a>(bin: &'a str, index: i64, value: &'a Value) -> Operation<'a> {
assert!(!value.is_nil());
let cdt_op = CdtOperation {
op: CdtOpType::ListSet,
args: vec![CdtArgument::Int(index), CdtArgument::Value(value)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn trim(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListTrim,
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn clear(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListClear,
args: vec![],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn increment(bin: &str, index: i64, value: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListIncrement,
args: vec![CdtArgument::Int(index), CdtArgument::Int(value)],
};
Operation {
op: OperationType::CdtWrite,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn size(bin: &str) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListSize,
args: vec![],
};
Operation {
op: OperationType::CdtRead,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListGet,
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtRead,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get_range(bin: &str, index: i64, count: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListGetRange,
args: vec![CdtArgument::Int(index), CdtArgument::Int(count)],
};
Operation {
op: OperationType::CdtRead,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}
pub fn get_range_from(bin: &str, index: i64) -> Operation {
let cdt_op = CdtOperation {
op: CdtOpType::ListGetRange,
args: vec![CdtArgument::Int(index)],
};
Operation {
op: OperationType::CdtRead,
bin: OperationBin::Name(bin),
data: OperationData::CdtListOp(cdt_op),
}
}