package containers

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A simple byte slice.

  • since 3.13.1
type t = {
  1. bs : bytes;
    (*

    The bytes, potentially shared between many slices

    *)
  2. mutable off : int;
    (*

    Offset in bs

    *)
  3. mutable len : int;
    (*

    Length of the slice. Valid indices are bs[off]…bs[off+len-1], inclusive.

    *)
}
val show : t -> string

Simple printer (summary, doesn't show the content)

val pp : Format.formatter -> t -> unit

Simple printer (summary, doesn't show the content)

val create : ?off:int -> ?len:int -> bytes -> t

create bs creates a slice of bs.

  • parameter off

    optional starting offset

  • parameter len

    length of the slice

val unsafe_of_string : ?off:int -> ?len:int -> string -> t

unsafe_of_string s makes a slice from a string. This is unsafe because mutating the bytes is forbidden (just like with Bytes.unsafe_of_string

val len : t -> int

Access the length

val get : t -> int -> char

get sl i gets the i-th byte of the slice. Same as sl.bs.[sl.off + i].

val set : t -> int -> char -> unit

set sl i c sets the i-th byte to c.

val consume : t -> int -> unit

consume sl n moves the offset forward by n bytes, and reduces len by n bytes.

val contents : t -> string

A copy of the contents of the slice. Allocates.

val sub : t -> int -> int -> t

sub sl off len makes a new slice with the same backing bs.

OCaml

Innovation. Community. Security.