Skip to content

Commit f5aa4de

Browse files
committed
add CCByte_buffer.to_slice
1 parent c29083c commit f5aa4de

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/core/CCByte_buffer.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ let[@inline] contents self = Bytes.sub_string self.bs 0 self.len
8989
let[@inline] contents_bytes self = Bytes.sub self.bs 0 self.len
9090
let[@inline] append_iter self i = i (add_char self)
9191
let[@inline] append_seq self seq = Seq.iter (add_char self) seq
92+
let[@inline] to_slice self = CCByte_slice.create ~len:self.len self.bs
9293

9394
let fold_left f acc self =
9495
let { bs; len } = self in

src/core/CCByte_buffer.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ val unsafe_get : t -> int -> char
6565
val set : t -> int -> char -> unit
6666
val unsafe_set : t -> int -> char -> unit
6767

68+
val to_slice : t -> CCByte_slice.t
69+
(** [to_slice buf] returns a slice of the current content.
70+
The slice shares the same byte array as [buf] (until [buf] is resized). *)
71+
6872
val contents : t -> string
6973
(** Copy the internal data to a string. Allocates. *)
7074

0 commit comments

Comments
 (0)