Module Vcs_eio_writer.Eio_writer

Writing to a Eio.Buf_write.t with an api that resembles Stdio or Async.Writer.

type t = Eio.Buf_write.t
val with_flow : ?initial_size:Base.int -> _ Eio.Flow.sink -> (t -> 'a) -> 'a

Same as Eio.Buf_write.with_flow.

Async writer style API

In this API, the emphasis is put on the prefix "write", rather than "print". "Print" sounds a bit like this is printing to the screen or the terminal, so it is reserved to the part of the API that prints to the standard channels (see below).

val write_string : t -> ?pos:Base.int -> ?len:Base.int -> Base.string -> Base.unit
val write_newline : t -> Base.unit
val write_line : t -> Base.string -> Base.unit
val write_lines : t -> Base.string Base.list -> Base.unit
val write_sexp : ?mach:Base.bool -> t -> Base.Sexp.t -> Base.unit

Write a sexp followed by a newline character. Default to mach:false, which means uses Sexp.to_string_hum by default.

val writef : t -> ('a, Stdlib.Format.formatter, Base.unit) Base.format -> 'a
val flush : t -> Base.unit

Stdio style API

There are cases where just need to print a quick statement to stdout or stderr, and going through building a complete call to with_flow feels too heavy. We assume that these functions are primarily useful in context where you have access to the eio env. The name exposed below are derived from OCaml's stdlib, and are good candidate for easily migrating some code.

val print_string : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.string -> Base.unit
val print_endline : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.string -> Base.unit
val print_newline : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.unit
val print_lines : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.string Base.list -> Base.unit

Write all strings in the order supplied to stdout, each followed by a newline char.

val prerr_string : env:< stderr : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.string -> Base.unit
val prerr_endline : env:< stderr : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.string -> Base.unit
val prerr_newline : env:< stderr : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> Base.unit

Format

val printf : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> ('a, Base.unit, Base.string, Base.unit) Base.format4 -> 'a
val aprintf : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> ('a, Stdlib.Format.formatter, Base.unit) Base.format -> 'a
val eprintf : env:< stderr : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> ('a, Base.unit, Base.string, Base.unit) Base.format4 -> 'a

Sexp

val print_sexp : env:< stdout : [> Eio.Flow.sink_ty ] Eio.Resource.t.. > -> ?mach:Base.bool -> Base.Sexp.t -> Base.unit

Print a sexp followed by a newline character. See Stdio.print_s. Default to mach:false, which means uses Sexp.to_string_hum by default.