<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>crates/printf/README.md - fork/fish-shell @ master</title>
<meta name="description" content="crates/printf/README.md in fork/fish-shell at master.">
<meta property="og:title" content="crates/printf/README.md - fork/fish-shell @ master">
<meta property="og:description" content="crates/printf/README.md in fork/fish-shell at master.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="master" data-tip="605c466379a074cf1b5cdb2b62bc8071aab8b47b">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/fish-shell</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/fish-shell</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">Johannes Altmanninger</span><span class="commit-message" data-commit="d26fd90efde31d7ea39bfd698cf00e437fb6bdbb">Merge pull request #11741, closes #11741</span><span class="snapshot-sha sha" data-commit="d26fd90efde31d7ea39bfd698cf00e437fb6bdbb">d26fd90ef</span><time datetime="2025-08-20T10:14:40+02:00" title="2025-08-20 10:14:40 +0200">2025-08-20</time></p>
<header class="topbar"><details class="switcher"><summary>master</summary><div class="menu"><strong>branches</strong><a class="current" href="/fork/fish-shell/ref/master/">master</a><a class="all" href="/fork/fish-shell/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/fish-shell/">fish-shell</a> / <a href="/fork/fish-shell/ref/master/tree/crates/">crates</a> / <a href="/fork/fish-shell/ref/master/tree/crates/printf/">printf</a> / <span class="cur">README.md</span></nav>
<span class="view-stats"><span>1.4 KiB</span><span>43 lines</span></span><span class="actions"><a class="raw" href="/fork/fish-shell/raw/9a7c07b7b92214104f1b765df032d93d90cbfe8b/crates/printf/README.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h1>fish-printf</h1>
<p>The printf implementation used in <a href="https://fishshell.com">fish-shell</a>, based on musl printf.</p>
<p><a href="https://crates.io/crates/fish-printf"><img src="https://img.shields.io/crates/v/fish-printf.svg" alt="crates.io" /></a></p>
<p>Licensed under the MIT license.</p>
<h3>Usage</h3>
<p>Run <code>cargo add fish-printf</code> to add this crate to your <code>Cargo.toml</code> file.</p>
<h3>Notes</h3>
<p>fish-printf attempts to match the C standard for printf. It supports the following features:</p>
<ul>
<li>Locale-specific formatting (decimal point, thousands separator, etc.)</li>
<li>Honors the current rounding mode.</li>
<li>Supports the <code>%n</code> modifier for counting characters written.</li>
</ul>
<p>fish-printf does not support positional arguments, such as <code>printf("%2$d", 1, 2)</code>.</p>
<p>Prefixes like <code>l</code> or <code>ll</code> are recognized, but only used for validating the format string.
The size of integer values is taken from the argument type.</p>
<p>fish-printf can output to an <code>std::fmt::Write</code> object, or return a string.</p>
<p>For reasons related to fish-shell, fish-printf has a feature "widestring" which uses the <a href="https://crates.io/crates/widestring">widestring</a> crate. This is off by default. If enabled, run <code>cargo add widestring</code> to add the widestring crate.</p>
<h3>Examples</h3>
<pre class="language-rust"><a-k>use</a-k> fish_printf<a-p>::</a-p>sprintf<a-p>;</a-p>

<a-c>// Create a `String` from a format string.</a-c>
<a-k>let</a-k> s = <a-m>sprintf!</a-m><a-p>(</a-p><a-s>&quot;%0.5g&quot;</a-s><a-p>,</a-p> <a-co>123456.0</a-co><a-p>)</a-p> <a-c>// 1.2346e+05</a-c>

<a-c>// Append to an existing string.</a-c><a-p>
</a-p><a-k>let</a-k><a-p> </a-p><a-k>mut</a-k><a-p> s = </a-p><a-t>String</a-t><a-p>::</a-p><a-f>new</a-f><a-p>();</a-p><a-p>
</a-p><a-m>sprintf!</a-m><a-p>(</a-p><a-p>=&gt; </a-p><a-o>&amp;</a-o><a-k>mut</a-k><a-p> s</a-p><a-p>,</a-p><a-p> </a-p><a-s>&quot;%0.5g&quot;</a-s><a-p>,</a-p><a-p> </a-p><a-co>123456.0</a-co><a-p>)</a-p><a-p> </a-p><a-c>// 1.2346e+05</a-c></pre>
<p>See the crate documentation for additional examples.</p>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>#</a-p> <a-tt>fish-printf</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">The printf implementation used in [fish-shell](https://fishshell.com), based on musl printf.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text">[![crates.io](https://img.shields.io/crates/v/fish-printf.svg)](https://crates.io/crates/fish-printf)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text">Licensed under the MIT license.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text"><a-p>###</a-p> <a-tt>Usage</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">Run `cargo add fish-printf` to add this crate to your `Cargo.toml` file.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text"><a-p>###</a-p> <a-tt>Notes</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text">fish-printf attempts to match the C standard for printf. It supports the following features:</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text"><a-p>-   </a-p>Locale-specific formatting (decimal point, thousands separator, etc.)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text"><a-p>-   </a-p>Honors the current rounding mode.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text"><a-p>-   </a-p>Supports the `%n` modifier for counting characters written.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text"><a-p>fish-printf does not support positional arguments, such as `printf(&quot;%2$d&quot;, 1, 2)`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"><a-p>Prefixes like `l` or `ll` are recognized, but only used for validating the format string.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"><a-p>The size of integer values is taken from the argument type.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text"><a-p>fish-printf can output to an `std::fmt::Write` object, or return a string.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"><a-p>For reasons related to fish-shell, fish-printf has a feature &quot;widestring&quot; which uses the [widestring](https://crates.io/crates/widestring) crate. This is off by default. If enabled, run `cargo add widestring` to add the widestring crate.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"><a-p>### </a-p><a-tt>Examples</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text"><a-p>```</a-p><a-tl>rust</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"><a-p>use fish_printf::sprintf;</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"><a-p>// Create a `String` from a format string.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>let s = </a-p><a-m>sprintf!</a-m><a-p>(</a-p><a-s>&quot;%0.5g&quot;</a-s><a-p>, </a-p><a-co>123456.0</a-co><a-p>) </a-p><a-c>// 1.2346e+05</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p>// Append to an existing string.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>let </a-p><a-k>mut</a-k><a-p> s = </a-p><a-t>String</a-t><a-p>::</a-p><a-f>new</a-f><a-p>();</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"><a-p>sprintf!(=&gt; </a-p><a-o>&amp;</a-o><a-k>mut</a-k><a-p> s, </a-p><a-s>&quot;%0.5g&quot;</a-s><a-p>, </a-p><a-co>123456.0</a-co><a-p>) </a-p><a-c>// 1.2346e+05</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text">See the crate documentation for additional examples.</span></span></pre></div></div>
</main>
</body>
</html>
