Module B0.Conv

module Conv: sig .. end
Textual and type-safe binary value conversions.


Converters


type 'a codec 
The type for type-safe binary codecs for values of type 'a.
val codec : (string -> 'a B0.result) * ('a -> string B0.result) -> 'a codec
codec (decode, encode) is a codec using decode to decode values from byte strings and encode to encode values to byte strings.
type 'a text 
The type for textual converters for values of type 'a.
val text : (string -> 'a B0.result) * 'a B0.Fmt.t -> 'a text
text (parse, print) is a textual converter using parse to parse text into values and print to pretty-print values. Note that print need not necessarily be the inverse of parse. See B0.Conv.v for details.
type 'a t 
The type for value converter for values of type 'a.
val v : ?docv:string -> ?codec:'a codec -> 'a text -> 'a t
v ~docv ~codec text is a value converter using text for textual conversions and codec for binary conversions. If codec is None the printer of text must be the inverse of its parser as it is used to derive a B0.Conv.codec. docv is a documentation meta-variable used in documentation to stand for the value, it defaults to "VALUE".
val with_docv : 'a t -> string -> 'a t
with_docv c docv is c with docv as a documentation meta-variable.
val parse : 'a t -> string -> 'a B0.result
parse c is c's textual parser.
val print : 'a t -> 'a B0.Fmt.t
print c is c's textual printer.
val decode : 'a t -> string -> 'a B0.result
decode c is c's binary decoder.
val encode : 'a t -> 'a -> string B0.result
encode c is c's binary encoder.
val docv : 'a t -> string
docv c is c 's documentation meta-variable.

Predefined converters


val bool : bool t
bool is a converter for booleans.
val char : char t
char is a convert for a single character.
val int : int t
int is a converter for ints.
val int32 : int32 t
int32 is a converter for int32.
val int64 : int64 t
int64 is a converter for int64.
val float : float t
float is a converter for floats.
val string : string t
string is a converter for strings.
val string_non_empty : string t
string_non_empty is a converter for non-empty strings.
val fpath : B0.Fpath.t t
fpath is a converter for file paths.
val file : B0.Fpath.t t
file is a converter for files. The file path is not checked for existence or non-directoryness.
val dir : B0.Fpath.t t
dir is a converter for directories. The directory path is not checked for existence or directoryness.
val tool : B0.Cmd.t t
tool is a converter for a command line tool name or file path. The resulting command line is non-empty and has no further arguments, see also B0.Conv.cmd. The tool is not checked for existence or executableness.
val cmd : B0.Cmd.t t
cmd is a converter for a command line parsed using B0.Cmd.of_string. Note that the result can be B0.Cmd.empty. See also B0.Conv.tool.
val enum : ?docv:string -> (string * 'a) list -> 'a t
enum ~docv alts derives a converter from the association list alts. alts should be a complete enumeration of the type 'a or Invalid_argument may be raised by B0.Conv.print or B0.Conv.encode.
val list : ?sep:string -> 'a t -> 'a list t
list ?sep c is a converter for lists of c.

Warning. Be aware of the following current limitations:


val pair : ?sep:string -> 'a t -> 'b t -> ('a * 'b) t
pair ?sep fst snd is a converter for pairs of fst and snd.

Warning. The warning of B0.Conv.list applies.

val option : ?none:string -> 'a t -> 'a option t
option c parses a c option using none (defaults to "") to denote None in textual converters. In a textual parse None is unconditionally returned on none, it takes over a potential decode of that string by c.
val some : 'a t -> 'a option t
option c wraps parses of c with Some _ note that this is exactly c: None can't be converted in either direction.