Tomlt_eioEio integration for Tomlt.
This module provides Eio-native functions for parsing and encoding TOML, with proper integration into Eio's exception system and system timezone support via ptime.clock.os.
Eio_main.run @@ fun env ->
let fs = Eio.Stdenv.fs env in
(* 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_eio.decode_file_exn config_codec Eio.Path.(fs / "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_eio.ptime ()) ~enc:(fun e -> e.time)
|> finish
))val err : Tomlt.Toml.Error.t -> exnerr e creates an Eio.Io exception from TOML error e.
wrap_error f runs f and converts Tomlt.Toml.Error.Error to Eio.Io.
val parse : ?file:string -> string -> Tomlt.Toml.tparse s parses TOML string s with Eio error handling.
val of_flow : ?file:string -> _ Eio.Flow.source -> Tomlt.Toml.tof_flow flow reads and parses TOML from an Eio flow.
val of_path : fs:_ Eio.Path.t -> string -> Tomlt.Toml.tof_path ~fs path reads and parses TOML from a file path.
val of_file : _ Eio.Path.t -> Tomlt.Toml.tof_file path reads and parses TOML from a file path.
val to_flow : _ Eio.Flow.sink -> Tomlt.Toml.t -> unitto_flow flow t writes TOML value t to an Eio flow.
val to_path : fs:_ Eio.Path.t -> string -> Tomlt.Toml.t -> unitto_path ~fs path t writes TOML value t to a file.
val to_file : _ Eio.Path.t -> Tomlt.Toml.t -> unitto_file path t writes TOML value t to a file.
Decode and encode typed values directly.
val decode_flow :
?file:string ->
'a Tomlt.t ->
_ Eio.Flow.source ->
('a, Tomlt.Toml.Error.t) resultdecode_flow codec flow reads TOML from flow and decodes with codec.
val decode_flow_exn : ?file:string -> 'a Tomlt.t -> _ Eio.Flow.source -> 'adecode_flow_exn codec flow is like decode_flow but raises on errors.
val decode_path :
'a Tomlt.t ->
fs:_ Eio.Path.t ->
string ->
('a, Tomlt.Toml.Error.t) resultdecode_path codec ~fs path reads a TOML file and decodes with codec.
val decode_path_exn : 'a Tomlt.t -> fs:_ Eio.Path.t -> string -> 'adecode_path_exn codec ~fs path is like decode_path but raises.
val decode_file : 'a Tomlt.t -> _ Eio.Path.t -> ('a, Tomlt.Toml.Error.t) resultdecode_file codec path reads a TOML file and decodes with codec.
val decode_file_exn : 'a Tomlt.t -> _ Eio.Path.t -> 'adecode_file_exn codec path is like decode_file but raises.
val encode_flow : 'a Tomlt.t -> 'a -> _ Eio.Flow.sink -> unitencode_flow codec value flow encodes value and writes to flow.
val encode_path : 'a Tomlt.t -> 'a -> fs:_ Eio.Path.t -> string -> unitencode_path codec value ~fs path encodes value and writes to a file.
val encode_file : 'a Tomlt.t -> 'a -> _ Eio.Path.t -> 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_eio.current_tz_offset_s
~now:Tomlt_eio.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_eio.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 ().