Skip to content
Snippets Groups Projects
Commit 4a0a0b86 authored by Éloïs's avatar Éloïs
Browse files

fix(kv_typed): deser empty bytes with get_ref_slice

parent 624b09ec
No related branches found
No related tags found
No related merge requests found
Pipeline #12708 passed
...@@ -67,11 +67,11 @@ mod tests { ...@@ -67,11 +67,11 @@ mod tests {
#[test] #[test]
fn test_btreeset_as_bytes() { fn test_btreeset_as_bytes() {
BTreeSet::<u64>::new().as_bytes(|bytes| assert_eq!(bytes, &[])); BTreeSet::<u64>::new().as_bytes(|bytes| assert!(bytes.is_empty()));
} }
#[test] #[test]
fn test_hashset_as_bytes() { fn test_hashset_as_bytes() {
HashSet::<u64>::new().as_bytes(|bytes| assert_eq!(bytes, &[])); HashSet::<u64>::new().as_bytes(|bytes| assert!(bytes.is_empty()));
} }
} }
......
...@@ -171,7 +171,9 @@ impl BackendCol for LevelDbCol { ...@@ -171,7 +171,9 @@ impl BackendCol for LevelDbCol {
self.0 self.0
.get(ReadOptions::new(), k_bytes)? .get(ReadOptions::new(), k_bytes)?
.map(|bytes| { .map(|bytes| {
if let Some(layout_verified) = if bytes.is_empty() {
f(&[])
} else if let Some(layout_verified) =
zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice( zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice(
&bytes[V::prefix_len()..], &bytes[V::prefix_len()..],
) )
......
...@@ -324,7 +324,9 @@ impl BackendCol for LmdbCol { ...@@ -324,7 +324,9 @@ impl BackendCol for LmdbCol {
.get::<_, [u8]>(&self.inner.tree, k_bytes) .get::<_, [u8]>(&self.inner.tree, k_bytes)
.to_opt()? .to_opt()?
.map(|bytes| { .map(|bytes| {
if let Some(layout_verified) = if bytes.is_empty() {
f(&[])
} else if let Some(layout_verified) =
zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice( zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice(
&bytes[V::prefix_len()..], &bytes[V::prefix_len()..],
) )
......
...@@ -138,7 +138,9 @@ impl BackendCol for MemCol { ...@@ -138,7 +138,9 @@ impl BackendCol for MemCol {
self.tree self.tree
.get(k_bytes) .get(k_bytes)
.map(|bytes| { .map(|bytes| {
if let Some(layout_verified) = if bytes.is_empty() {
f(&[])
} else if let Some(layout_verified) =
zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice( zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice(
&bytes[V::prefix_len()..], &bytes[V::prefix_len()..],
) )
......
...@@ -121,7 +121,9 @@ impl BackendCol for MemCol { ...@@ -121,7 +121,9 @@ impl BackendCol for MemCol {
self.0 self.0
.as_ref() .as_ref()
.map(|bytes| { .map(|bytes| {
if let Some(layout_verified) = if bytes.is_empty() {
f(&[])
} else if let Some(layout_verified) =
zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice(&bytes[V::prefix_len()..]) zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice(&bytes[V::prefix_len()..])
{ {
f(&layout_verified) f(&layout_verified)
......
...@@ -121,7 +121,9 @@ impl BackendCol for SledCol { ...@@ -121,7 +121,9 @@ impl BackendCol for SledCol {
self.0 self.0
.get(k_bytes)? .get(k_bytes)?
.map(|bytes| { .map(|bytes| {
if let Some(layout_verified) = if bytes.is_empty() {
f(&[])
} else if let Some(layout_verified) =
zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice( zerocopy::LayoutVerified::<_, [V::Elem]>::new_slice(
&bytes[V::prefix_len()..], &bytes[V::prefix_len()..],
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment