|
1 | | -use std::borrow::Cow; |
2 | 1 | use std::ops::{Bound, RangeBounds}; |
3 | 2 | use std::{any, fmt, marker, mem, ptr}; |
4 | 3 |
|
@@ -425,16 +424,16 @@ impl<KC, DC, C> Database<KC, DC, C> { |
425 | 424 | pub fn get_duplicates<'a, 'txn>( |
426 | 425 | &self, |
427 | 426 | txn: &'txn RoTxn, |
428 | | - key: &'a KC::EItem, |
| 427 | + key: &'a KC::SelfType, |
429 | 428 | ) -> Result<Option<RoIter<'txn, KC, DC, MoveOnCurrentKeyDuplicates>>> |
430 | 429 | where |
431 | | - KC: BytesEncode<'a>, |
| 430 | + KC: ToBytes<'a>, |
432 | 431 | { |
433 | 432 | assert_eq_env_db_txn!(self, txn); |
434 | 433 |
|
435 | 434 | let mut cursor = RoCursor::new(txn, self.dbi)?; |
436 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
437 | | - if cursor.move_on_key(&key_bytes)? { |
| 435 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 436 | + if cursor.move_on_key(key_bytes.as_ref())? { |
438 | 437 | Ok(Some(RoIter::new(cursor))) |
439 | 438 | } else { |
440 | 439 | Ok(None) |
@@ -488,17 +487,17 @@ impl<KC, DC, C> Database<KC, DC, C> { |
488 | 487 | pub fn get_lower_than<'a, 'txn>( |
489 | 488 | &self, |
490 | 489 | txn: &'txn RoTxn, |
491 | | - key: &'a KC::EItem, |
| 490 | + key: &'a KC::SelfType, |
492 | 491 | ) -> Result<Option<(KC::DItem, DC::DItem)>> |
493 | 492 | where |
494 | | - KC: BytesEncode<'a> + BytesDecode<'txn>, |
| 493 | + KC: ToBytes<'a> + BytesDecode<'txn>, |
495 | 494 | DC: BytesDecode<'txn>, |
496 | 495 | { |
497 | 496 | assert_eq_env_db_txn!(self, txn); |
498 | 497 |
|
499 | 498 | let mut cursor = RoCursor::new(txn, self.dbi)?; |
500 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
501 | | - cursor.move_on_key_greater_than_or_equal_to(&key_bytes)?; |
| 499 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 500 | + cursor.move_on_key_greater_than_or_equal_to(key_bytes.as_ref())?; |
502 | 501 |
|
503 | 502 | match cursor.move_on_prev(MoveOperation::NoDup) { |
504 | 503 | Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { |
@@ -557,18 +556,19 @@ impl<KC, DC, C> Database<KC, DC, C> { |
557 | 556 | pub fn get_lower_than_or_equal_to<'a, 'txn>( |
558 | 557 | &self, |
559 | 558 | txn: &'txn RoTxn, |
560 | | - key: &'a KC::EItem, |
| 559 | + key: &'a KC::SelfType, |
561 | 560 | ) -> Result<Option<(KC::DItem, DC::DItem)>> |
562 | 561 | where |
563 | | - KC: BytesEncode<'a> + BytesDecode<'txn>, |
| 562 | + KC: ToBytes<'a> + BytesDecode<'txn>, |
564 | 563 | DC: BytesDecode<'txn>, |
565 | 564 | { |
566 | 565 | assert_eq_env_db_txn!(self, txn); |
567 | 566 |
|
568 | 567 | let mut cursor = RoCursor::new(txn, self.dbi)?; |
569 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
570 | | - let result = match cursor.move_on_key_greater_than_or_equal_to(&key_bytes) { |
571 | | - Ok(Some((key, data))) if key == &key_bytes[..] => Ok(Some((key, data))), |
| 568 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 569 | + let key_bytes = key_bytes.as_ref(); |
| 570 | + let result = match cursor.move_on_key_greater_than_or_equal_to(key_bytes) { |
| 571 | + Ok(Some((key, data))) if key == key_bytes => Ok(Some((key, data))), |
572 | 572 | Ok(_) => cursor.move_on_prev(MoveOperation::NoDup), |
573 | 573 | Err(e) => Err(e), |
574 | 574 | }; |
@@ -630,18 +630,19 @@ impl<KC, DC, C> Database<KC, DC, C> { |
630 | 630 | pub fn get_greater_than<'a, 'txn>( |
631 | 631 | &self, |
632 | 632 | txn: &'txn RoTxn, |
633 | | - key: &'a KC::EItem, |
| 633 | + key: &'a KC::SelfType, |
634 | 634 | ) -> Result<Option<(KC::DItem, DC::DItem)>> |
635 | 635 | where |
636 | | - KC: BytesEncode<'a> + BytesDecode<'txn>, |
| 636 | + KC: ToBytes<'a> + BytesDecode<'txn>, |
637 | 637 | DC: BytesDecode<'txn>, |
638 | 638 | { |
639 | 639 | assert_eq_env_db_txn!(self, txn); |
640 | 640 |
|
641 | 641 | let mut cursor = RoCursor::new(txn, self.dbi)?; |
642 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
643 | | - let entry = match cursor.move_on_key_greater_than_or_equal_to(&key_bytes)? { |
644 | | - Some((key, data)) if key > &key_bytes[..] => Some((key, data)), |
| 642 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 643 | + let key_bytes = key_bytes.as_ref(); |
| 644 | + let entry = match cursor.move_on_key_greater_than_or_equal_to(key_bytes)? { |
| 645 | + Some((key, data)) if key > key_bytes => Some((key, data)), |
645 | 646 | Some((_key, _data)) => cursor.move_on_next(MoveOperation::NoDup)?, |
646 | 647 | None => None, |
647 | 648 | }; |
@@ -702,17 +703,17 @@ impl<KC, DC, C> Database<KC, DC, C> { |
702 | 703 | pub fn get_greater_than_or_equal_to<'a, 'txn>( |
703 | 704 | &self, |
704 | 705 | txn: &'txn RoTxn, |
705 | | - key: &'a KC::EItem, |
| 706 | + key: &'a KC::SelfType, |
706 | 707 | ) -> Result<Option<(KC::DItem, DC::DItem)>> |
707 | 708 | where |
708 | | - KC: BytesEncode<'a> + BytesDecode<'txn>, |
| 709 | + KC: ToBytes<'a> + BytesDecode<'txn>, |
709 | 710 | DC: BytesDecode<'txn>, |
710 | 711 | { |
711 | 712 | assert_eq_env_db_txn!(self, txn); |
712 | 713 |
|
713 | 714 | let mut cursor = RoCursor::new(txn, self.dbi)?; |
714 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
715 | | - match cursor.move_on_key_greater_than_or_equal_to(&key_bytes) { |
| 715 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 716 | + match cursor.move_on_key_greater_than_or_equal_to(key_bytes.as_ref()) { |
716 | 717 | Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { |
717 | 718 | (Ok(key), Ok(data)) => Ok(Some((key, data))), |
718 | 719 | (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), |
@@ -1498,31 +1499,32 @@ impl<KC, DC, C> Database<KC, DC, C> { |
1498 | 1499 | range: &'a R, |
1499 | 1500 | ) -> Result<RwRevRange<'txn, KC, DC>> |
1500 | 1501 | where |
1501 | | - KC: BytesEncode<'a>, |
1502 | | - R: RangeBounds<KC::EItem>, |
| 1502 | + KC: ToBytes<'a>, |
| 1503 | + R: RangeBounds<KC::SelfType>, |
1503 | 1504 | { |
1504 | 1505 | assert_eq_env_db_txn!(self, txn); |
1505 | 1506 |
|
| 1507 | + // TODO optimize, this might do unnecessary allocations on types that are already 'static |
1506 | 1508 | let start_bound = match range.start_bound() { |
1507 | 1509 | Bound::Included(bound) => { |
1508 | | - let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; |
1509 | | - Bound::Included(bytes.into_owned()) |
| 1510 | + let bytes = KC::to_bytes(bound).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1511 | + Bound::Included(bytes.into()) |
1510 | 1512 | } |
1511 | 1513 | Bound::Excluded(bound) => { |
1512 | | - let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; |
1513 | | - Bound::Excluded(bytes.into_owned()) |
| 1514 | + let bytes = KC::to_bytes(bound).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1515 | + Bound::Excluded(bytes.into()) |
1514 | 1516 | } |
1515 | 1517 | Bound::Unbounded => Bound::Unbounded, |
1516 | 1518 | }; |
1517 | 1519 |
|
1518 | 1520 | let end_bound = match range.end_bound() { |
1519 | 1521 | Bound::Included(bound) => { |
1520 | | - let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; |
1521 | | - Bound::Included(bytes.into_owned()) |
| 1522 | + let bytes = KC::to_bytes(bound).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1523 | + Bound::Included(bytes.into()) |
1522 | 1524 | } |
1523 | 1525 | Bound::Excluded(bound) => { |
1524 | | - let bytes = KC::bytes_encode(bound).map_err(Error::Encoding)?; |
1525 | | - Bound::Excluded(bytes.into_owned()) |
| 1526 | + let bytes = KC::to_bytes(bound).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1527 | + Bound::Excluded(bytes.into()) |
1526 | 1528 | } |
1527 | 1529 | Bound::Unbounded => Bound::Unbounded, |
1528 | 1530 | }; |
@@ -1650,16 +1652,17 @@ impl<KC, DC, C> Database<KC, DC, C> { |
1650 | 1652 | pub fn prefix_iter_mut<'a, 'txn>( |
1651 | 1653 | &self, |
1652 | 1654 | txn: &'txn mut RwTxn, |
1653 | | - prefix: &'a KC::EItem, |
| 1655 | + prefix: &'a KC::SelfType, |
1654 | 1656 | ) -> Result<RwPrefix<'txn, KC, DC, C>> |
1655 | 1657 | where |
1656 | | - KC: BytesEncode<'a>, |
| 1658 | + KC: ToBytes<'a>, |
1657 | 1659 | C: LexicographicComparator, |
1658 | 1660 | { |
1659 | 1661 | assert_eq_env_db_txn!(self, txn); |
1660 | 1662 |
|
1661 | | - let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; |
1662 | | - let prefix_bytes = prefix_bytes.into_owned(); |
| 1663 | + let prefix_bytes = KC::to_bytes(prefix).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1664 | + // TODO optimize, this might do unnecessary allocations on types that are already 'static |
| 1665 | + let prefix_bytes = prefix_bytes.into(); |
1663 | 1666 | RwCursor::new(txn, self.dbi).map(|cursor| RwPrefix::new(cursor, prefix_bytes)) |
1664 | 1667 | } |
1665 | 1668 |
|
@@ -1783,16 +1786,17 @@ impl<KC, DC, C> Database<KC, DC, C> { |
1783 | 1786 | pub fn rev_prefix_iter_mut<'a, 'txn>( |
1784 | 1787 | &self, |
1785 | 1788 | txn: &'txn mut RwTxn, |
1786 | | - prefix: &'a KC::EItem, |
| 1789 | + prefix: &'a KC::SelfType, |
1787 | 1790 | ) -> Result<RwRevPrefix<'txn, KC, DC, C>> |
1788 | 1791 | where |
1789 | | - KC: BytesEncode<'a>, |
| 1792 | + KC: ToBytes<'a>, |
1790 | 1793 | C: LexicographicComparator, |
1791 | 1794 | { |
1792 | 1795 | assert_eq_env_db_txn!(self, txn); |
1793 | 1796 |
|
1794 | | - let prefix_bytes = KC::bytes_encode(prefix).map_err(Error::Encoding)?; |
1795 | | - let prefix_bytes = prefix_bytes.into_owned(); |
| 1797 | + let prefix_bytes = KC::to_bytes(prefix).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1798 | + // TODO optimize, this might do unnecessary allocations on types that are already 'static |
| 1799 | + let prefix_bytes = prefix_bytes.into(); |
1796 | 1800 | RwCursor::new(txn, self.dbi).map(|cursor| RwRevPrefix::new(cursor, prefix_bytes)) |
1797 | 1801 | } |
1798 | 1802 |
|
@@ -1896,18 +1900,18 @@ impl<KC, DC, C> Database<KC, DC, C> { |
1896 | 1900 | pub fn put_reserved<'a, F>( |
1897 | 1901 | &self, |
1898 | 1902 | txn: &mut RwTxn, |
1899 | | - key: &'a KC::EItem, |
| 1903 | + key: &'a KC::SelfType, |
1900 | 1904 | data_size: usize, |
1901 | 1905 | write_func: F, |
1902 | 1906 | ) -> Result<()> |
1903 | 1907 | where |
1904 | | - KC: BytesEncode<'a>, |
| 1908 | + KC: ToBytes<'a>, |
1905 | 1909 | F: FnOnce(&mut ReservedSpace) -> io::Result<()>, |
1906 | 1910 | { |
1907 | 1911 | assert_eq_env_db_txn!(self, txn); |
1908 | 1912 |
|
1909 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
1910 | | - let mut key_val = unsafe { crate::into_val(&key_bytes) }; |
| 1913 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 1914 | + let mut key_val = unsafe { crate::into_val(key_bytes.as_ref()) }; |
1911 | 1915 | let mut reserved = ffi::reserve_size_val(data_size); |
1912 | 1916 | let flags = ffi::MDB_RESERVE; |
1913 | 1917 |
|
@@ -1987,20 +1991,20 @@ impl<KC, DC, C> Database<KC, DC, C> { |
1987 | 1991 | &self, |
1988 | 1992 | txn: &mut RwTxn, |
1989 | 1993 | flags: PutFlags, |
1990 | | - key: &'a KC::EItem, |
1991 | | - data: &'a DC::EItem, |
| 1994 | + key: &'a KC::SelfType, |
| 1995 | + data: &'a DC::SelfType, |
1992 | 1996 | ) -> Result<()> |
1993 | 1997 | where |
1994 | | - KC: BytesEncode<'a>, |
1995 | | - DC: BytesEncode<'a>, |
| 1998 | + KC: ToBytes<'a>, |
| 1999 | + DC: ToBytes<'a>, |
1996 | 2000 | { |
1997 | 2001 | assert_eq_env_db_txn!(self, txn); |
1998 | 2002 |
|
1999 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
2000 | | - let data_bytes: Cow<[u8]> = DC::bytes_encode(data).map_err(Error::Encoding)?; |
| 2003 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 2004 | + let data_bytes = DC::to_bytes(data).map_err(|err| Error::Encoding(Box::new(err)))?; |
2001 | 2005 |
|
2002 | | - let mut key_val = unsafe { crate::into_val(&key_bytes) }; |
2003 | | - let mut data_val = unsafe { crate::into_val(&data_bytes) }; |
| 2006 | + let mut key_val = unsafe { crate::into_val(key_bytes.as_ref()) }; |
| 2007 | + let mut data_val = unsafe { crate::into_val(data_bytes.as_ref()) }; |
2004 | 2008 | let flags = flags.bits(); |
2005 | 2009 |
|
2006 | 2010 | unsafe { |
@@ -2046,12 +2050,12 @@ impl<KC, DC, C> Database<KC, DC, C> { |
2046 | 2050 | pub fn get_or_put<'a, 'txn>( |
2047 | 2051 | &'txn self, |
2048 | 2052 | txn: &mut RwTxn, |
2049 | | - key: &'a KC::EItem, |
2050 | | - data: &'a DC::EItem, |
| 2053 | + key: &'a KC::SelfType, |
| 2054 | + data: &'a DC::SelfType, |
2051 | 2055 | ) -> Result<Option<DC::DItem>> |
2052 | 2056 | where |
2053 | | - KC: BytesEncode<'a>, |
2054 | | - DC: BytesEncode<'a> + BytesDecode<'a>, |
| 2057 | + KC: ToBytes<'a>, |
| 2058 | + DC: ToBytes<'a> + BytesDecode<'a>, |
2055 | 2059 | { |
2056 | 2060 | self.get_or_put_with_flags(txn, PutFlags::empty(), key, data) |
2057 | 2061 | } |
@@ -2094,20 +2098,20 @@ impl<KC, DC, C> Database<KC, DC, C> { |
2094 | 2098 | &'txn self, |
2095 | 2099 | txn: &mut RwTxn, |
2096 | 2100 | flags: PutFlags, |
2097 | | - key: &'a KC::EItem, |
2098 | | - data: &'a DC::EItem, |
| 2101 | + key: &'a KC::SelfType, |
| 2102 | + data: &'a DC::SelfType, |
2099 | 2103 | ) -> Result<Option<DC::DItem>> |
2100 | 2104 | where |
2101 | | - KC: BytesEncode<'a>, |
2102 | | - DC: BytesEncode<'a> + BytesDecode<'a>, |
| 2105 | + KC: ToBytes<'a>, |
| 2106 | + DC: ToBytes<'a> + BytesDecode<'a>, |
2103 | 2107 | { |
2104 | 2108 | assert_eq_env_db_txn!(self, txn); |
2105 | 2109 |
|
2106 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
2107 | | - let data_bytes: Cow<[u8]> = DC::bytes_encode(data).map_err(Error::Encoding)?; |
| 2110 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 2111 | + let data_bytes = DC::to_bytes(data).map_err(|err| Error::Encoding(Box::new(err)))?; |
2108 | 2112 |
|
2109 | | - let mut key_val = unsafe { crate::into_val(&key_bytes) }; |
2110 | | - let mut data_val = unsafe { crate::into_val(&data_bytes) }; |
| 2113 | + let mut key_val = unsafe { crate::into_val(key_bytes.as_ref()) }; |
| 2114 | + let mut data_val = unsafe { crate::into_val(data_bytes.as_ref()) }; |
2111 | 2115 | let flags = (flags | PutFlags::NO_OVERWRITE).bits(); |
2112 | 2116 |
|
2113 | 2117 | let result = unsafe { |
@@ -2178,12 +2182,12 @@ impl<KC, DC, C> Database<KC, DC, C> { |
2178 | 2182 | pub fn get_or_put_reserved<'a, 'txn, F>( |
2179 | 2183 | &'txn self, |
2180 | 2184 | txn: &mut RwTxn, |
2181 | | - key: &'a KC::EItem, |
| 2185 | + key: &'a KC::SelfType, |
2182 | 2186 | data_size: usize, |
2183 | 2187 | write_func: F, |
2184 | 2188 | ) -> Result<Option<DC::DItem>> |
2185 | 2189 | where |
2186 | | - KC: BytesEncode<'a>, |
| 2190 | + KC: ToBytes<'a>, |
2187 | 2191 | F: FnOnce(&mut ReservedSpace) -> io::Result<()>, |
2188 | 2192 | DC: BytesDecode<'a>, |
2189 | 2193 | { |
@@ -2243,20 +2247,20 @@ impl<KC, DC, C> Database<KC, DC, C> { |
2243 | 2247 | &'txn self, |
2244 | 2248 | txn: &mut RwTxn, |
2245 | 2249 | flags: PutFlags, |
2246 | | - key: &'a KC::EItem, |
| 2250 | + key: &'a KC::SelfType, |
2247 | 2251 | data_size: usize, |
2248 | 2252 | write_func: F, |
2249 | 2253 | ) -> Result<Option<DC::DItem>> |
2250 | 2254 | where |
2251 | | - KC: BytesEncode<'a>, |
| 2255 | + KC: ToBytes<'a>, |
2252 | 2256 | F: FnOnce(&mut ReservedSpace) -> io::Result<()>, |
2253 | 2257 | DC: BytesDecode<'a>, |
2254 | 2258 | { |
2255 | 2259 | assert_eq_env_db_txn!(self, txn); |
2256 | 2260 |
|
2257 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
| 2261 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
2258 | 2262 |
|
2259 | | - let mut key_val = unsafe { crate::into_val(&key_bytes) }; |
| 2263 | + let mut key_val = unsafe { crate::into_val(key_bytes.as_ref()) }; |
2260 | 2264 | let mut reserved = ffi::reserve_size_val(data_size); |
2261 | 2265 | let flags = (flags | PutFlags::NO_OVERWRITE).bits() | lmdb_master_sys::MDB_RESERVE; |
2262 | 2266 |
|
@@ -2328,14 +2332,14 @@ impl<KC, DC, C> Database<KC, DC, C> { |
2328 | 2332 | /// wtxn.commit()?; |
2329 | 2333 | /// # Ok(()) } |
2330 | 2334 | /// ``` |
2331 | | - pub fn delete<'a>(&self, txn: &mut RwTxn, key: &'a KC::EItem) -> Result<bool> |
| 2335 | + pub fn delete<'a>(&self, txn: &mut RwTxn, key: &'a KC::SelfType) -> Result<bool> |
2332 | 2336 | where |
2333 | | - KC: BytesEncode<'a>, |
| 2337 | + KC: ToBytes<'a>, |
2334 | 2338 | { |
2335 | 2339 | assert_eq_env_db_txn!(self, txn); |
2336 | 2340 |
|
2337 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
2338 | | - let mut key_val = unsafe { crate::into_val(&key_bytes) }; |
| 2341 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 2342 | + let mut key_val = unsafe { crate::into_val(key_bytes.as_ref()) }; |
2339 | 2343 |
|
2340 | 2344 | let result = unsafe { |
2341 | 2345 | mdb_result(ffi::mdb_del(txn.txn.txn, self.dbi, &mut key_val, ptr::null_mut())) |
@@ -2410,19 +2414,19 @@ impl<KC, DC, C> Database<KC, DC, C> { |
2410 | 2414 | pub fn delete_one_duplicate<'a>( |
2411 | 2415 | &self, |
2412 | 2416 | txn: &mut RwTxn, |
2413 | | - key: &'a KC::EItem, |
2414 | | - data: &'a DC::EItem, |
| 2417 | + key: &'a KC::SelfType, |
| 2418 | + data: &'a DC::SelfType, |
2415 | 2419 | ) -> Result<bool> |
2416 | 2420 | where |
2417 | | - KC: BytesEncode<'a>, |
2418 | | - DC: BytesEncode<'a>, |
| 2421 | + KC: ToBytes<'a>, |
| 2422 | + DC: ToBytes<'a>, |
2419 | 2423 | { |
2420 | 2424 | assert_eq_env_db_txn!(self, txn); |
2421 | 2425 |
|
2422 | | - let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?; |
2423 | | - let data_bytes: Cow<[u8]> = DC::bytes_encode(data).map_err(Error::Encoding)?; |
2424 | | - let mut key_val = unsafe { crate::into_val(&key_bytes) }; |
2425 | | - let mut data_val = unsafe { crate::into_val(&data_bytes) }; |
| 2426 | + let key_bytes = KC::to_bytes(key).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 2427 | + let data_bytes = DC::to_bytes(data).map_err(|err| Error::Encoding(Box::new(err)))?; |
| 2428 | + let mut key_val = unsafe { crate::into_val(key_bytes.as_ref()) }; |
| 2429 | + let mut data_val = unsafe { crate::into_val(data_bytes.as_ref()) }; |
2426 | 2430 |
|
2427 | 2431 | let result = |
2428 | 2432 | unsafe { mdb_result(ffi::mdb_del(txn.txn.txn, self.dbi, &mut key_val, &mut data_val)) }; |
|
0 commit comments