Skip to content

Commit

Permalink
Revert "refactor: merge Tuple and TupleBuffer"
Browse files Browse the repository at this point in the history
Reason: the commit introduces too many breaking changes but not enough
value to justify them.

This reverts commit 7b16d84.
  • Loading branch information
gmoshkin committed May 24, 2024
1 parent 12f3e36 commit 638fda8
Show file tree
Hide file tree
Showing 26 changed files with 350 additions and 840 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

### Changed

- `Tuple` was heavily refactored and now represents both TupleBuffer and Tarantool tuple.
- `tarantool::error::TarantoolError` is renamed `BoxError`. The old name is
still available via a type alias, and is not yet deprecated so as not to break
too much code, but in future it will be deprecated.
Expand Down Expand Up @@ -115,7 +114,6 @@
but `tarantool::error::Error`, `Box<dyn Error>` & even `String` still work.
- `tarantool::set_error!` macro now returns `()` instead of `-1_i32` as it did previously
- `tarantool::tuple::Tuple::decode` does not support partial decoding anymore. Also any methods/functions which use rpm_serde have same effect.
- `ToTupleBuffer` trait renamed to `ToTuple` and now returns `Tuple`.

### Added (picodata)

Expand Down
2 changes: 1 addition & 1 deletion examples/read/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fn read() {
let result = space.get(&(key,)).unwrap();
assert!(result.is_some());

let result = result.unwrap().decode_rmp::<Row>().unwrap();
let result = result.unwrap().decode::<Row>().unwrap();
println!("value={:?}", result);
}
2 changes: 1 addition & 1 deletion examples/tokio-hyper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn start_server() {
let fruit = space_fruit
.select(IteratorType::All, &())
.unwrap()
.map(|t| t.decode_rmp::<Fruit>().unwrap())
.map(|t| t.decode::<Fruit>().unwrap())
.collect();
fruit_tx.send(fruit).unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions tarantool/src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,14 +1387,14 @@ mod tests {
let t: Tuple = crate::lua_state()
.eval("return box.tuple.new(require('decimal').new('-8.11'))")
.unwrap();
let (d,): (Decimal,) = t.decode_rmp().unwrap();
let (d,): (Decimal,) = t.decode().unwrap();
assert_eq!(d.to_string(), "-8.11");
}

#[crate::test(tarantool = "crate")]
pub fn to_tuple() {
let d = decimal!(-8.11);
let t = Tuple::encode_rmp([d]).unwrap();
let t = Tuple::new(&[d]).unwrap();
let lua = crate::lua_state();
let f: tlua::LuaFunction<_> = lua.eval("return box.tuple.unpack").unwrap();
let d: Decimal = f.call_with_args(&t).unwrap();
Expand Down
56 changes: 28 additions & 28 deletions tarantool/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::error::{Error, TarantoolError, TarantoolErrorCode};
use crate::ffi::tarantool as ffi;
use crate::msgpack;
use crate::space::{Space, SpaceId, SystemSpace};
use crate::tuple::{Encode, ToTuple, Tuple, TupleBuffer};
use crate::tuple::{Encode, ToTupleBuffer, Tuple, TupleBuffer};
use crate::tuple::{KeyDef, KeyDefPart};
use crate::tuple_from_box_api;
use crate::unwrap_or;
Expand Down Expand Up @@ -529,7 +529,7 @@ impl Index {
)
.into());
};
tuple.decode_rmp::<Metadata>()
tuple.decode::<Metadata>()
}

// Drops index.
Expand All @@ -548,12 +548,12 @@ impl Index {
#[inline]
pub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let buf;
let data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
buf = key.to_tuple()?.to_vec();
buf = key.to_tuple_buffer()?;
buf.as_ref()
});
let Range { start, end } = data.as_ptr_range();
Expand All @@ -578,9 +578,9 @@ impl Index {
#[inline]
pub fn select<K>(&self, iterator_type: IteratorType, key: &K) -> Result<IndexIterator, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let key_buf: TupleBuffer = key.to_tuple().unwrap().into();
let key_buf = key.to_tuple_buffer().unwrap();
let Range { start, end } = key_buf.as_ref().as_ptr_range();

let ptr = unsafe {
Expand Down Expand Up @@ -614,12 +614,12 @@ impl Index {
#[inline]
pub fn delete<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let buf;
let data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
buf = key.to_tuple()?.to_vec();
buf = key.to_tuple_buffer()?;
buf.as_ref()
});
let Range { start, end } = data.as_ptr_range();
Expand Down Expand Up @@ -649,13 +649,13 @@ impl Index {
#[inline]
pub fn update<K, Op>(&self, key: &K, ops: impl AsRef<[Op]>) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
Op: ToTuple,
K: ToTupleBuffer + ?Sized,
Op: ToTupleBuffer,
{
let key_buf;
let key_data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
key_buf = key.to_tuple()?.to_vec();
key_buf = key.to_tuple_buffer()?;
key_buf.as_ref()
});
let mut ops_buf = Vec::with_capacity(4 + ops.as_ref().len() * 4);
Expand All @@ -668,12 +668,12 @@ impl Index {
#[deprecated = "use update_raw instead"]
pub unsafe fn update_mp<K>(&self, key: &K, ops: &[Vec<u8>]) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let key_buf;
let key_data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
key_buf = key.to_tuple()?.to_vec();
key_buf = key.to_tuple_buffer()?;
key_buf.as_ref()
});
let mut ops_buf = Vec::with_capacity(128);
Expand Down Expand Up @@ -711,13 +711,13 @@ impl Index {
#[inline]
pub fn upsert<T, Op>(&self, value: &T, ops: impl AsRef<[Op]>) -> Result<(), Error>
where
T: ToTuple + ?Sized,
Op: ToTuple,
T: ToTupleBuffer + ?Sized,
Op: ToTupleBuffer,
{
let value_buf;
let value_data = unwrap_or!(value.tuple_data(), {
// TODO: use region allocation for this
value_buf = value.to_tuple()?.to_vec();
value_buf = value.to_tuple_buffer()?;
value_buf.as_ref()
});
let mut ops_buf = Vec::with_capacity(4 + ops.as_ref().len() * 4);
Expand All @@ -730,12 +730,12 @@ impl Index {
#[deprecated = "use upsert_raw instead"]
pub unsafe fn upsert_mp<T>(&self, value: &T, ops: &[Vec<u8>]) -> Result<(), Error>
where
T: ToTuple + ?Sized,
T: ToTupleBuffer + ?Sized,
{
let value_buf;
let value_data = unwrap_or!(value.tuple_data(), {
// TODO: use region allocation for this
value_buf = value.to_tuple()?.to_vec();
value_buf = value.to_tuple_buffer()?;
value_buf.as_ref()
});
let mut ops_buf = Vec::with_capacity(128);
Expand Down Expand Up @@ -819,12 +819,12 @@ impl Index {
#[inline]
pub fn min<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let buf;
let data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
buf = key.to_tuple()?.to_vec();
buf = key.to_tuple_buffer()?;
buf.as_ref()
});
let Range { start, end } = data.as_ptr_range();
Expand All @@ -847,12 +847,12 @@ impl Index {
#[inline]
pub fn max<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let buf;
let data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
buf = key.to_tuple()?.to_vec();
buf = key.to_tuple_buffer()?;
buf.as_ref()
});
let Range { start, end } = data.as_ptr_range();
Expand All @@ -874,12 +874,12 @@ impl Index {
#[inline]
pub fn count<K>(&self, iterator_type: IteratorType, key: &K) -> Result<usize, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let buf;
let data = unwrap_or!(key.tuple_data(), {
// TODO: use region allocation for this
buf = key.to_tuple()?.to_vec();
buf = key.to_tuple_buffer()?;
buf.as_ref()
});
let Range { start, end } = data.as_ptr_range();
Expand Down Expand Up @@ -1143,21 +1143,21 @@ mod tests {

assert!(key_def
.compare_with_key(
&Tuple::encode_rmp(("foo", 13, "bar", 37)).unwrap(),
&Tuple::new(&("foo", 13, "bar", 37)).unwrap(),
&("foo", 13, "bar", 37),
)
.is_eq());

assert!(key_def
.compare_with_key(
&Tuple::encode_rmp(("foo", 13, "bar", 37)).unwrap(),
&Tuple::new(&("foo", 13, "bar", 37)).unwrap(),
&("foo", 14, "bar", 37),
)
.is_lt());

assert!(key_def
.compare_with_key(
&Tuple::encode_rmp(("foo", 13, "baz", 37)).unwrap(),
&Tuple::new(&("foo", 13, "baz", 37)).unwrap(),
&("foo", 13, "bar", 37),
)
.is_gt());
Expand All @@ -1170,7 +1170,7 @@ mod tests {
let sys_index = Space::from(SystemSpace::Index);
for tuple in sys_index.select(IteratorType::All, &()).unwrap() {
// Check index metadata is deserializable from what is actually in _index
let _meta: Metadata = tuple.decode_rmp().unwrap();
let _meta: Metadata = tuple.decode().unwrap();
}
}
}
3 changes: 2 additions & 1 deletion tarantool/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use std::ptr::null;
use log::{Level, Log, Metadata, Record};

use crate::ffi::tarantool as ffi;
use crate::util::{into_cstring_lossy, to_cstring_lossy};
use crate::util::into_cstring_lossy;
use crate::util::to_cstring_lossy;

/// [Log](https://docs.rs/log/latest/log/trait.Log.html) trait implementation. Wraps [say()](fn.say.html).
pub struct TarantoolLogger(fn(Level) -> SayLevel);
Expand Down
6 changes: 3 additions & 3 deletions tarantool/src/msgpack.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::tuple::ToTuple;
use super::tuple::ToTupleBuffer;
use crate::unwrap_ok_or;
use crate::Result;
use std::io::Cursor;
Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn skip_value(cur: &mut (impl Read + Seek)) -> Result<()> {
/// Write to `w` a msgpack array with values from `arr`.
pub fn write_array<T>(w: &mut impl std::io::Write, arr: &[T]) -> Result<()>
where
T: ToTuple,
T: ToTupleBuffer,
{
rmp::encode::write_array_len(w, arr.len() as _)?;
for elem in arr {
Expand Down Expand Up @@ -256,7 +256,7 @@ where
#[inline(always)]
pub fn push_tuple<T>(&mut self, v: &T) -> Result<()>
where
T: ToTuple + ?Sized,
T: ToTupleBuffer + ?Sized,
{
v.write_tuple_data(&mut self.writer)?;
self.len += 1;
Expand Down
12 changes: 6 additions & 6 deletions tarantool/src/net_box/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::vec::IntoIter;
use crate::error::Error;
use crate::index::IteratorType;
use crate::network::protocol;
use crate::tuple::{Encode, ToTuple, Tuple};
use crate::tuple::{Encode, ToTupleBuffer, Tuple};

use super::inner::ConnInner;
use super::Options;
Expand All @@ -30,7 +30,7 @@ impl RemoteIndex {
#[inline(always)]
pub fn get<K>(&self, key: &K, options: &Options) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
Ok(self
.select(
Expand All @@ -55,7 +55,7 @@ impl RemoteIndex {
options: &Options,
) -> Result<RemoteIndexIterator, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
let rows = self.conn_inner.request(
&protocol::Select {
Expand Down Expand Up @@ -83,7 +83,7 @@ impl RemoteIndex {
options: &Options,
) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
Op: Encode,
{
self.conn_inner.request(
Expand All @@ -107,7 +107,7 @@ impl RemoteIndex {
options: &Options,
) -> Result<Option<Tuple>, Error>
where
T: ToTuple + ?Sized,
T: ToTupleBuffer + ?Sized,
Op: Encode,
{
self.conn_inner.request(
Expand All @@ -125,7 +125,7 @@ impl RemoteIndex {
/// (see [details](../index/struct.Index.html#method.delete)).
pub fn delete<K>(&self, key: &K, options: &Options) -> Result<Option<Tuple>, Error>
where
K: ToTuple + ?Sized,
K: ToTupleBuffer + ?Sized,
{
self.conn_inner.request(
&protocol::Delete {
Expand Down
Loading

0 comments on commit 638fda8

Please sign in to comment.