byte_slice: add clear and of_string

This commit is contained in:
Simon Cruanes 2026-04-09 00:58:12 +00:00
parent c02c76eb0b
commit 749f973528
2 changed files with 12 additions and 0 deletions

View file

@ -21,6 +21,12 @@ let create ?(off = 0) ?len bs =
let[@inline] unsafe_of_string ?off ?len s =
create ?off ?len (Bytes.unsafe_of_string s)
let[@inline] of_string s = create (Bytes.of_string s)
let[@inline] clear self =
self.off <- 0;
self.len <- 0
let[@inline] len self = self.len
let[@inline] contents self = Bytes.sub_string self.bs self.off self.len

View file

@ -26,6 +26,12 @@ val unsafe_of_string : ?off:int -> ?len:int -> string -> t
This is unsafe because mutating the bytes is forbidden
(just like with {!Bytes.unsafe_of_string} *)
val of_string : string -> t
(** [of_string s] makes a slice from a copy of [s]. Safe to mutate. *)
val clear : t -> unit
(** [clear sl] resets [off] and [len] to 0. *)
val len : t -> int
(** Access the length *)