Tomlt_unixUnix integration for Tomlt.
This module provides Unix-native functions for parsing and encoding TOML files using standard channels, with system timezone support via ptime.clock.os.
(* Read and decode a config file *)
type config = { host : string; port : int }
let config_codec = Tomlt.(Table.(
obj (fun host port -> { host; port })
|> mem "host" string ~enc:(fun c -> c.host)
|> mem "port" int ~enc:(fun c -> c.port)
|> finish
))
let config = Tomlt_unix.decode_file_exn config_codec "config.toml"
(* With datetime using system timezone *)
type event = { name : string; time : Ptime.t }
let event_codec = Tomlt.(Table.(
obj (fun name time -> { name; time })
|> mem "name" string ~enc:(fun e -> e.name)
|> mem "time" (Tomlt_unix.ptime ()) ~enc:(fun e -> e.time)
|> finish
))Read and write TOML files directly.
val of_file : string -> Tomlt.Toml.tof_file path reads and parses a TOML file.
val to_file : string -> Tomlt.Toml.t -> unitto_file path value writes value as TOML to a file.
Read and write TOML via standard channels.
val of_channel : ?file:string -> in_channel -> Tomlt.Toml.tof_channel ic reads and parses TOML from an input channel.
val to_channel : out_channel -> Tomlt.Toml.t -> unitto_channel oc value writes value as TOML to an output channel.
Decode and encode typed values directly to/from files.
val decode_file : 'a Tomlt.t -> string -> ('a, Tomlt.Toml.Error.t) resultdecode_file codec path reads a TOML file and decodes it with codec.
val decode_file_exn : 'a Tomlt.t -> string -> 'adecode_file_exn codec path is like decode_file but raises on errors.
val encode_file : 'a Tomlt.t -> 'a -> string -> unitencode_file codec value path encodes value and writes to a file.
Pre-configured datetime codecs that use the system timezone. These are convenience wrappers around Tomlt.ptime and Tomlt.ptime_full with ~get_tz:current_tz_offset_s and ~now already applied.
ptime () is a datetime codec using the system timezone.
Equivalent to:
Tomlt.ptime ~get_tz:Tomlt_unix.current_tz_offset_s
~now:Tomlt_unix.now ()val ptime_full : unit -> Tomlt.Toml.ptime_datetime Tomlt.tptime_full () preserves datetime variant information using system timezone.
Equivalent to:
Tomlt.ptime_full ~get_tz:Tomlt_unix.current_tz_offset_s ()Low-level time functions. Prefer using ptime and ptime_full for datetime handling.
current_tz_offset_s () returns the current system timezone offset in seconds from UTC. Returns Some offset where positive values are east of UTC (e.g., 3600 for +01:00) and negative values are west.
val now : unit -> Ptime.tnow () returns the current time as a Ptime.t.
val today_date : ?tz_offset_s:int -> unit -> Ptime.datetoday_date ?tz_offset_s () returns today's date as (year, month, day). If tz_offset_s is not provided, uses current_tz_offset_s ().