File tree Expand file tree Collapse file tree 4 files changed +47
-8
lines changed
Expand file tree Collapse file tree 4 files changed +47
-8
lines changed Original file line number Diff line number Diff line change 22name = " byteview"
33description = " Thin, immutable zero-copy slice type"
44license = " MIT OR Apache-2.0"
5- version = " 0.7 .0"
5+ version = " 0.8 .0"
66edition = " 2021"
7- rust-version = " 1.74 "
7+ rust-version = " 1.81 "
88readme = " README.md"
99include = [" src/**/*" , " LICENSE-APACHE" , " LICENSE-MIT" , " README.md" ]
1010repository = " https://github.com/fjall-rs/byteview"
@@ -28,9 +28,6 @@ rand = "0.9.0"
2828# TODO: Need MSRV 1.81
2929# rkyv = { version = "0.8.10", features = ["bytecheck", "unaligned"] }
3030
31- # half 2.5.0 has MSRV 1.81
32- half = " =2.4.0"
33-
3431[[bench ]]
3532name = " bench"
3633harness = false
Original file line number Diff line number Diff line change 1+ use crate :: ByteView ;
2+
3+ /// A builder for a [`ByteView`] that allows mutation before freezing it.
4+ pub struct Builder ( ByteView ) ;
5+
6+ impl Builder {
7+ /// Creates a new builder.
8+ #[ must_use]
9+ pub const fn new ( inner : ByteView ) -> Self {
10+ Self ( inner)
11+ }
12+
13+ /// Converts the builder into a [`ByteView`], making it immutable.
14+ #[ must_use]
15+ pub fn freeze ( mut self ) -> ByteView {
16+ self . 0 . update_prefix ( ) ;
17+ self . 0
18+ }
19+ }
20+
21+ impl std:: ops:: Deref for Builder {
22+ type Target = [ u8 ] ;
23+
24+ fn deref ( & self ) -> & Self :: Target {
25+ & self . 0
26+ }
27+ }
28+
29+ impl std:: ops:: DerefMut for Builder {
30+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
31+ self . 0 . get_mut_slice ( )
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ use std::{
1212 } ,
1313} ;
1414
15+ pub use crate :: builder:: Builder ;
16+
1517#[ cfg( target_pointer_width = "64" ) ]
1618const INLINE_SIZE : usize = 20 ;
1719
@@ -207,6 +209,12 @@ impl Drop for Mutator<'_> {
207209}
208210
209211impl ByteView {
212+ #[ doc( hidden) ]
213+ #[ must_use]
214+ pub fn builder_unzeroed ( len : usize ) -> Builder {
215+ Builder :: new ( Self :: with_size_unzeroed ( len) )
216+ }
217+
210218 fn prefix ( & self ) -> & [ u8 ] {
211219 let len = PREFIX_SIZE . min ( self . len ( ) ) ;
212220
@@ -218,7 +226,7 @@ impl ByteView {
218226 self . len ( ) <= INLINE_SIZE
219227 }
220228
221- fn update_prefix ( & mut self ) {
229+ pub ( crate ) fn update_prefix ( & mut self ) {
222230 if !self . is_inline ( ) {
223231 unsafe {
224232 let slice_ptr: & [ u8 ] = & * self ;
@@ -639,7 +647,7 @@ impl ByteView {
639647 unsafe { self . trailer . short . len as usize }
640648 }
641649
642- fn get_mut_slice ( & mut self ) -> & mut [ u8 ] {
650+ pub ( crate ) fn get_mut_slice ( & mut self ) -> & mut [ u8 ] {
643651 let len = self . len ( ) ;
644652
645653 if self . is_inline ( ) {
Original file line number Diff line number Diff line change 4747 clippy:: needless_lifetimes
4848) ]
4949
50+ mod builder;
5051mod byteview;
5152mod strview;
5253
5354pub use { byteview:: ByteView , strview:: StrView } ;
5455
5556#[ doc( hidden) ]
56- pub use byteview:: Mutator ;
57+ pub use byteview:: { Builder , Mutator } ;
You can’t perform that action at this time.
0 commit comments