moonpool/lwt/Lwt_fmt/index.html
2024-12-04 16:11:59 +00:00

20 lines
13 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Lwt_fmt (lwt.Lwt_fmt)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.3"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../index.html">lwt</a> &#x00BB; Lwt_fmt</nav><header class="odoc-preamble"><h1>Module <code><span>Lwt_fmt</span></code></h1><p>Format API for Lwt-powered IOs</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.1.0</li></ul></header><nav class="odoc-toc"><ul><li><a href="#formatters">Formatters</a><ul><li><a href="#printing">Printing</a></li></ul></li></ul></nav><div class="odoc-content"><p>This module bridges the gap between <a href="../../ocaml/Stdlib/Format/index.html"><code>Stdlib.Format</code></a> and <a href="../Lwt/index.html"><code>Lwt</code></a>. Although it is not required, it is recommended to use this module with the <a href="https://erratique.ch/software/fmt"><code>Fmt</code></a> library.</p><p>Compared to regular formatting function, the main difference is that printing statements will now return promises instead of blocking.</p><div class="odoc-spec"><div class="spec value anchored" id="val-printf"><a href="#val-printf" class="anchor"></a><code><span><span class="keyword">val</span> printf : <span><span><span>(<span class="type-var">'a</span>, <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a>, unit, <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span>)</span> <a href="../../ocaml/Stdlib/index.html#type-format4">format4</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Returns a promise that prints on the standard output. Similar to <a href="../../ocaml/Stdlib/Format/index.html#val-printf"><code>Stdlib.Format.printf</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-eprintf"><a href="#val-eprintf" class="anchor"></a><code><span><span class="keyword">val</span> eprintf : <span><span><span>(<span class="type-var">'a</span>, <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a>, unit, <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span>)</span> <a href="../../ocaml/Stdlib/index.html#type-format4">format4</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Returns a promise that prints on the standard error. Similar to <a href="../../ocaml/Stdlib/Format/index.html#val-eprintf"><code>Stdlib.Format.eprintf</code></a>.</p></div></div><h2 id="formatters"><a href="#formatters" class="anchor"></a>Formatters</h2><div class="odoc-spec"><div class="spec type anchored" id="type-formatter"><a href="#type-formatter" class="anchor"></a><code><span><span class="keyword">type</span> formatter</span></code></div><div class="spec-doc"><p>Lwt enabled formatters</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-order"><a href="#type-order" class="anchor"></a><code><span><span class="keyword">type</span> order</span><span> = </span></code><ol><li id="type-order.String" class="def variant constructor anchored"><a href="#type-order.String" class="anchor"></a><code><span>| </span><span><span class="constructor">String</span> <span class="keyword">of</span> string * int * int</span></code><div class="def-doc"><span class="comment-delim">(*</span><p><code>String (s, off, len)</code> indicate the output of <code>s</code> at offset <code>off</code> and length <code>len</code>.</p><span class="comment-delim">*)</span></div></li><li id="type-order.Flush" class="def variant constructor anchored"><a href="#type-order.Flush" class="anchor"></a><code><span>| </span><span><span class="constructor">Flush</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Flush operation</p><span class="comment-delim">*)</span></div></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make_stream"><a href="#val-make_stream" class="anchor"></a><code><span><span class="keyword">val</span> make_stream : <span>unit <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-order">order</a> <a href="../Lwt_stream/index.html#type-t">Lwt_stream.t</a></span> * <a href="#type-formatter">formatter</a></span></code></div><div class="spec-doc"><p><code>make_stream ()</code> returns a formatter and a stream of all the writing order given on that stream.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_channel"><a href="#val-of_channel" class="anchor"></a><code><span><span class="keyword">val</span> of_channel : <span><a href="../Lwt_io/index.html#type-output_channel">Lwt_io.output_channel</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-formatter">formatter</a></span></code></div><div class="spec-doc"><p><code>of_channel oc</code> creates a formatter that writes to the channel <code>oc</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stdout"><a href="#val-stdout" class="anchor"></a><code><span><span class="keyword">val</span> stdout : <a href="#type-formatter">formatter</a></span></code></div><div class="spec-doc"><p>Formatter printing on <a href="../Lwt_io/index.html#val-stdout"><code>Lwt_io.stdout</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stderr"><a href="#val-stderr" class="anchor"></a><code><span><span class="keyword">val</span> stderr : <a href="#type-formatter">formatter</a></span></code></div><div class="spec-doc"><p>Formatter printing on <a href="../Lwt_io/index.html#val-stdout"><code>Lwt_io.stdout</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make_formatter"><a href="#val-make_formatter" class="anchor"></a><code><span><span class="keyword">val</span> make_formatter :
<span><span class="label">commit</span>:<span>(<span>unit <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">fmt</span>:<a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<a href="#type-formatter">formatter</a></span></code></div><div class="spec-doc"><p><code>make_formatter ~commit ~fmt</code> creates a new lwt formatter based on the <a href="../../ocaml/Stdlib/Format/index.html#type-formatter"><code>Stdlib.Format.formatter</code></a> <code>fmt</code>. The <code>commit</code> function will be called by the printing functions to update the underlying channel.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_formatter"><a href="#val-get_formatter" class="anchor"></a><code><span><span class="keyword">val</span> get_formatter : <span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span> <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a></span></code></div><div class="spec-doc"><p><code>get_formatter fmt</code> returns the underlying <a href="../../ocaml/Stdlib/Format/index.html#type-formatter"><code>Stdlib.Format.formatter</code></a>. To access the underlying formatter during printing, it is recommended to use <code>%t</code> and <code>%a</code>.</p></div></div><h3 id="printing"><a href="#printing" class="anchor"></a>Printing</h3><div class="odoc-spec"><div class="spec value anchored" id="val-fprintf"><a href="#val-fprintf" class="anchor"></a><code><span><span class="keyword">val</span> fprintf :
<span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span>
<span><span><span>(<span class="type-var">'a</span>, <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a>, unit, <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span>)</span> <a href="../../ocaml/Stdlib/index.html#type-format4">format4</a></span> <span class="arrow">&#45;&gt;</span></span>
<span class="type-var">'a</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-kfprintf"><a href="#val-kfprintf" class="anchor"></a><code><span><span class="keyword">val</span> kfprintf :
<span><span>(<span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span> <span><span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span>
<span><span><span>(<span class="type-var">'b</span>, <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a>, unit, <span class="type-var">'a</span>)</span> <a href="../../ocaml/Stdlib/index.html#type-format4">format4</a></span> <span class="arrow">&#45;&gt;</span></span>
<span class="type-var">'b</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-ifprintf"><a href="#val-ifprintf" class="anchor"></a><code><span><span class="keyword">val</span> ifprintf :
<span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span>
<span><span><span>(<span class="type-var">'a</span>, <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a>, unit, <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span>)</span> <a href="../../ocaml/Stdlib/index.html#type-format4">format4</a></span> <span class="arrow">&#45;&gt;</span></span>
<span class="type-var">'a</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-ikfprintf"><a href="#val-ikfprintf" class="anchor"></a><code><span><span class="keyword">val</span> ikfprintf :
<span><span>(<span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span> <span><span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span>
<span><span><span>(<span class="type-var">'b</span>, <a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a>, unit, <span class="type-var">'a</span>)</span> <a href="../../ocaml/Stdlib/index.html#type-format4">format4</a></span> <span class="arrow">&#45;&gt;</span></span>
<span class="type-var">'b</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-flush"><a href="#val-flush" class="anchor"></a><code><span><span class="keyword">val</span> flush : <span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>flush fmt</code> flushes the formatter (as with <a href="../../ocaml/Stdlib/Format/index.html#val-pp_print_flush"><code>Stdlib.Format.pp_print_flush</code></a>) and executes all the printing action on the underlying channel.</p></div></div><p>Low level functions</p><div class="odoc-spec"><div class="spec value anchored" id="val-write_order"><a href="#val-write_order" class="anchor"></a><code><span><span class="keyword">val</span> write_order : <span><a href="../Lwt_io/index.html#type-output_channel">Lwt_io.output_channel</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-order">order</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>write_order oc o</code> applies the order <code>o</code> on the channel <code>oc</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-write_pending"><a href="#val-write_pending" class="anchor"></a><code><span><span class="keyword">val</span> write_pending : <span><a href="#type-formatter">formatter</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p>Write all the pending orders of a formatter. Warning: This function flush neither the internal format queues nor the underlying channel and is intended for low level use only. You should probably use <a href="#val-flush"><code>flush</code></a> instead.</p></div></div></div></body></html>