summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/dune3
-rw-r--r--lib/common/format.ml10
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/common/dune b/lib/common/dune
new file mode 100644
index 0000000..d070694
--- /dev/null
+++ b/lib/common/dune
@@ -0,0 +1,3 @@
+(library
+ (name croquette_common)
+ (libraries))
diff --git a/lib/common/format.ml b/lib/common/format.ml
new file mode 100644
index 0000000..5245dd0
--- /dev/null
+++ b/lib/common/format.ml
@@ -0,0 +1,10 @@
+(** [format_string f] call the function [f] with a fresh formatter and return
+ the content as a string *)
+let format_string : (Stdlib.Format.formatter -> unit) -> string =
+ fun f ->
+ let buff = Buffer.create 16 in
+ let format = Stdlib.Format.formatter_of_buffer buff in
+ let () = f format in
+
+ Stdlib.Format.pp_print_flush format ();
+ Buffer.contents buff