Skip to content

Commit

Permalink
fix kani tests; cleanup; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
somethingelseentirely committed Nov 25, 2024
1 parent 0145b7c commit 6ddc885
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anybytes"
version = "0.10.0-alpha.1"
version = "0.10.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/triblespace/anybytes"
Expand Down
12 changes: 8 additions & 4 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,21 @@ impl Bytes {
let owner = Arc::new(owner);

Self {
// This is safe because slices always have a non-null address.
data,
owner,
}
}

/// Creates `Bytes` from a [`ByteOwner`] + [`ByteSource`] (for example, `Vec<u8>`).
pub fn from_owning_source(owner: impl ByteSource + ByteOwner) -> Self {
let arc = Arc::new(owner);
Self::from_owning_source_arc(arc)
let owner = Arc::new(owner);
let data = owner.as_bytes();
// Erase the lifetime.
let data = unsafe { erase_lifetime(data) };
Self {
data,
owner,
}
}

/// Creates `Bytes` from an `Arc<ByteSource + ByteOwner>`.
Expand All @@ -126,7 +131,6 @@ impl Bytes {
// Erase the lifetime.
let data = unsafe { erase_lifetime(data) };
Self {
// This is safe because slices always have a non-null address.
data,
owner: arc,
}
Expand Down
12 changes: 8 additions & 4 deletions src/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod verification {
#[kani::unwind(33)]
pub fn check_static() {
let owner: &'static [u8] = &STATIC_U8;
let bytes = Bytes::from_owner(owner);
let bytes = Bytes::from_owning_source(owner);
let bytes_slice: &[u8] = &bytes;
assert_eq!(owner, bytes_slice)
}
Expand All @@ -207,7 +207,7 @@ mod verification {
pub fn check_box() {
let owner: Box<[u8]> = STATIC_U8.into();
let arc = Arc::new(owner);
let bytes = Bytes::from_arc(arc.clone());
let bytes = Bytes::from_owning_source_arc(arc.clone());
let arc_slice: &[u8] = &arc;
let bytes_slice: &[u8] = &bytes;
assert_eq!(arc_slice, bytes_slice)
Expand All @@ -233,8 +233,10 @@ mod verification {
#[kani::proof]
#[kani::unwind(513)]
pub fn check_static_zeroconf() {
use crate::Bytes;

let owner: &'static [ComplexZC] = &STATIC_ZC;
let bytes = Bytes::from_owner(owner);
let bytes = Bytes::from_owning_source(owner);
let bytes_slice: &[u8] = &bytes;
assert_eq!(owner.as_bytes(), bytes_slice)
}
Expand All @@ -243,9 +245,11 @@ mod verification {
#[kani::proof]
#[kani::unwind(513)]
pub fn check_box_zeroconf() {
use crate::Bytes;

let owner: Box<[ComplexZC]> = STATIC_ZC.into();
let arc = Arc::new(owner);
let bytes = Bytes::from_arc(arc.clone());
let bytes = Bytes::from_owning_source_arc(arc.clone());
let arc_slice: &[u8] = arc.as_bytes();
let bytes_slice: &[u8] = &bytes;
assert_eq!(arc_slice, bytes_slice)
Expand Down

0 comments on commit 6ddc885

Please sign in to comment.