@@ -9,14 +9,41 @@ type t = {
99 (* * Length of the slice. Valid indices are [bs[off]…bs[off+len-1]],
1010 inclusive. *)
1111}
12- [@@ deriving show ]
12+
13+ val show : t -> string
14+ (* * Simple printer (summary, doesn't show the content) *)
15+
16+ val pp : Format .formatter -> t -> unit
17+ (* * Simple printer (summary, doesn't show the content) *)
1318
1419val create : ?off : int -> ?len : int -> bytes -> t
15- val clear : t -> unit
16- val of_string : string -> t
20+ (* * [create bs] creates a slice of [bs].
21+ @param off optional starting offset
22+ @param len length of the slice *)
23+
24+ val unsafe_of_string : ?off : int -> ?len : int -> string -> t
25+ (* * [unsafe_of_string s] makes a slice from a string.
26+ This is unsafe because mutating the bytes is forbidden
27+ (just like with {!Bytes.unsafe_of_string} *)
28+
1729val len : t -> int
30+ (* * Access the length *)
31+
1832val get : t -> int -> char
33+ (* * [get sl i] gets the [i]-th byte of the slice. Same as [sl.bs.[sl.off + i]].
34+ @raise Invalid_argument if out of bounds. *)
35+
1936val set : t -> int -> char -> unit
37+ (* * [set sl i c] sets the [i]-th byte to [c].
38+ @raise Invalid_argument if out of bounds. *)
39+
2040val consume : t -> int -> unit
41+ (* * [consume sl n] moves the offset forward by [n] bytes, and
42+ reduces [len] by [n] bytes. *)
43+
2144val contents : t -> string
45+ (* * A copy of the contents of the slice. Allocates. *)
46+
2247val sub : t -> int -> int -> t
48+ (* * [sub sl off len] makes a new slice with the same
49+ backing [bs]. *)
0 commit comments