Skip to content

Commit 9ffc07d

Browse files
committed
Add Eio_unix.Stdenv.with_env for updating environments
1 parent 7695d22 commit 9ffc07d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib_eio/unix/eio_unix.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,25 @@ module Stdenv = struct
4747
debug : Eio.Debug.t;
4848
backend_id: string;
4949
>
50+
51+
let with_env
52+
?stdin ?stdout ?stderr ?net ?domain_mgr
53+
?process_mgr ?clock ?mono_clock ?fs ?cwd
54+
?secure_random ?debug ?backend_id (env : base) : base
55+
=
56+
object
57+
method stdin = Option.value ~default:env#stdin stdin
58+
method stdout = Option.value ~default:env#stdout stdout
59+
method stderr = Option.value ~default:env#stderr stderr
60+
method net = Option.value ~default:env#net net
61+
method domain_mgr = Option.value ~default:env#domain_mgr domain_mgr
62+
method process_mgr = Option.value ~default:env#process_mgr process_mgr
63+
method clock = Option.value ~default:env#clock clock
64+
method mono_clock = Option.value ~default:env#mono_clock mono_clock
65+
method fs = Option.value ~default:env#fs fs
66+
method cwd = Option.value ~default:env#cwd cwd
67+
method secure_random = Option.value ~default:env#secure_random secure_random
68+
method debug = Option.value ~default:env#debug debug
69+
method backend_id = Option.value ~default:env#backend_id backend_id
70+
end
5071
end

lib_eio/unix/eio_unix.mli

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ module Stdenv : sig
8989
(** The common set of features provided by all traditional operating systems (BSDs, Linux, Mac, Windows).
9090
9191
You can use the functions in {!Eio.Stdenv} to access these fields if you prefer. *)
92+
93+
val with_env :
94+
?stdin:source_ty r ->
95+
?stdout:sink_ty r ->
96+
?stderr:sink_ty r ->
97+
?net:[ `Generic | `Unix ] Eio.Net.ty r ->
98+
?domain_mgr:Eio.Domain_manager.ty r ->
99+
?process_mgr:Process.mgr_ty r ->
100+
?clock:float Eio.Time.clock_ty r ->
101+
?mono_clock:Eio.Time.Mono.ty r ->
102+
?fs:Eio.Fs.dir_ty Eio.Path.t ->
103+
?cwd:Eio.Fs.dir_ty Eio.Path.t ->
104+
?secure_random:Eio.Flow.source_ty r ->
105+
?debug:Eio.Debug.t ->
106+
?backend_id:string ->
107+
base ->
108+
base
109+
(** [with_env env] allows you to replace parts of [env] with new resources.
110+
111+
By default it will select the resource from [env]. *)
92112
end
93113

94114
(** API for Eio backends only. *)

0 commit comments

Comments
 (0)