325 lines
23 KiB
HTML
325 lines
23 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<!-- This file is generated by Nim. -->
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<!-- Favicon -->
|
|
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
|
|
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
|
|
|
|
<!-- Google fonts -->
|
|
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
|
|
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
|
|
|
|
<!-- CSS -->
|
|
<title>op</title>
|
|
<link rel="stylesheet" type="text/css" href="nimdoc.out.css">
|
|
|
|
<script type="text/javascript" src="dochack.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
function main() {
|
|
var pragmaDots = document.getElementsByClassName("pragmadots");
|
|
for (var i = 0; i < pragmaDots.length; i++) {
|
|
pragmaDots[i].onclick = function(event) {
|
|
// Hide tease
|
|
event.target.parentNode.style.display = "none";
|
|
// Show actual
|
|
event.target.parentNode.nextElementSibling.style.display = "inline";
|
|
}
|
|
}
|
|
|
|
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
|
|
function switchTheme(e) {
|
|
if (e.target.checked) {
|
|
document.documentElement.setAttribute('data-theme', 'dark');
|
|
localStorage.setItem('theme', 'dark');
|
|
} else {
|
|
document.documentElement.setAttribute('data-theme', 'light');
|
|
localStorage.setItem('theme', 'light');
|
|
}
|
|
}
|
|
|
|
toggleSwitch.addEventListener('change', switchTheme, false);
|
|
|
|
|
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
document.documentElement.setAttribute('data-theme', "dark");
|
|
toggleSwitch.checked = true;
|
|
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
|
document.documentElement.setAttribute('data-theme', "light");
|
|
toggleSwitch.checked = false;
|
|
} else {
|
|
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
|
|
if (currentTheme) {
|
|
document.documentElement.setAttribute('data-theme', currentTheme);
|
|
|
|
if (currentTheme === 'dark') {
|
|
toggleSwitch.checked = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</head>
|
|
<body onload="main()">
|
|
<div class="document" id="documentId">
|
|
<div class="container">
|
|
<h1 class="title">op</h1>
|
|
<div class="row">
|
|
<div class="three columns">
|
|
<div class="theme-switch-wrapper">
|
|
<label class="theme-switch" for="checkbox">
|
|
<input type="checkbox" id="checkbox" />
|
|
<div class="slider round"></div>
|
|
</label>
|
|
<em>Dark Mode</em>
|
|
</div>
|
|
<div id="global-links">
|
|
<ul class="simple">
|
|
</ul>
|
|
</div>
|
|
<div id="searchInputDiv">
|
|
Search: <input type="text" id="searchInput"
|
|
onkeyup="search()" />
|
|
</div>
|
|
<div>
|
|
Group by:
|
|
<select onchange="groupBy(this.value)">
|
|
<option value="section">Section</option>
|
|
<option value="type">Type</option>
|
|
</select>
|
|
</div>
|
|
<ul class="simple simple-toc" id="toc-list">
|
|
<li><a class="reference" id="basic-usage_toc" href="#basic-usage">Basic Usage</a></li>
|
|
<li>
|
|
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#Either"
|
|
title="Either[A; B] = object
|
|
case isA*: bool
|
|
of true:
|
|
a*: A
|
|
|
|
of false:
|
|
b*: B"><wbr />Either<span class="attachedType"></span></a></li>
|
|
<li><a class="reference" href="#OP"
|
|
title="OP[T] = Either[T, string]"><wbr />OP<span class="attachedType"></span></a></li>
|
|
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<a class="reference reference-toplevel" href="#18" id="68">Templates</a>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#checkA.t%2CEither"
|
|
title="checkA(self: Either): bool"><wbr />check<wbr />A<span class="attachedType">Either</span></a></li>
|
|
<li><a class="reference" href="#getA.t%2CEither%5BA%2CB%5D"
|
|
title="getA[A; B](self: Either[A, B]): A"><wbr />get<wbr />A<span class="attachedType">Either</span></a></li>
|
|
<li><a class="reference" href="#getB.t%2CEither%5BA%2CB%5D"
|
|
title="getB[A; B](self: Either[A, B]): B"><wbr />get<wbr />B<span class="attachedType">Either</span></a></li>
|
|
<li><a class="reference" href="#isOK.t%2COP"
|
|
title="isOK(self: OP): bool"><wbr />is<wbr />OK<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#val.t%2COP"
|
|
title="val(self: OP): auto"><wbr />val<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#error.t%2COP"
|
|
title="error(self: OP): auto"><wbr />error<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#ok.t%2CT"
|
|
title="ok[T](val: T): OP[T]"><wbr />ok<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#ok.t%2COP%5BT%5D%2CT"
|
|
title="ok[T](self: var OP[T]; val: T)"><wbr />ok<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#fail.t%2C%2Cstring"
|
|
title="fail[T; ](O: type OP[T]; msg: string): O:type"><wbr />fail<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#fail.t%2Ctypedesc%2Cstring"
|
|
title="fail(T: typedesc; msg: string): OP[T]"><wbr />fail<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#fail.t%2COP%2Cstring"
|
|
title="fail(op: OP; msg: string): OP"><wbr />fail<span class="attachedType">OP</span></a></li>
|
|
<li><a class="reference" href="#fail.t%2Cstatic%5Bstring%5D"
|
|
title="fail(msg: static[string]): auto"><wbr />fail<span class="attachedType"></span></a></li>
|
|
|
|
</ul>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
<div class="nine columns" id="content">
|
|
<div id="tocRoot"></div>
|
|
|
|
<p class="module-desc"><table class="docinfo" frame="void" rules="none"><col class="docinfo-name" /><col class="docinfo-content" /><tbody valign="top"><tr><th class="docinfo-name">Version:</th><td> 1.0.0</td></tr>
|
|
<tr><th class="docinfo-name">Author:</th><td> luxick <op@luxick.de></td></tr>
|
|
</tbody></table><p>OP stands for "Operation Result".</p>
|
|
<p>This module contains a generic type that can be used as a return type for operations that could fail. It adds additional messages to the result.</p>
|
|
<p>This module improves upon the <a class="reference external" href="https://nim-lang.org/docs/options.html">options module</a> in that additional messages can be passed along with the presence or absence of a value.</p>
|
|
|
|
<h1><a class="toc-backref" id="basic-usage" href="#basic-usage">Basic Usage</a></h1><pre class="listing"><span class="Keyword">proc</span> <span class="Identifier">divide</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">OP</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span> <span class="Operator">=</span>
|
|
<span class="Comment">## This could fail</span>
|
|
<span class="Keyword">if</span> <span class="Identifier">b</span> <span class="Operator">==</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
|
|
<span class="Keyword">return</span> <span class="Identifier">fail</span> <span class="StringLit">"Cannot divide by zero!"</span>
|
|
<span class="Keyword">else</span><span class="Punctuation">:</span>
|
|
<span class="Keyword">return</span> <span class="Identifier">ok</span> <span class="Identifier">a</span> <span class="Operator">/</span> <span class="Identifier">b</span> <span class="Comment"># Wrap the result</span>
|
|
|
|
<span class="Keyword">let</span> <span class="Identifier">r</span> <span class="Operator">=</span> <span class="Identifier">divide</span><span class="Punctuation">(</span><span class="DecNumber">42</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">r</span><span class="Operator">.</span><span class="Identifier">isOk</span> <span class="Operator">==</span> <span class="Identifier">false</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">r</span><span class="Operator">.</span><span class="Identifier">error</span> <span class="Operator">==</span> <span class="StringLit">"Cannot divide by zero!"</span></pre></p>
|
|
<div class="section" id="7">
|
|
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
|
<dl class="item">
|
|
<a id="Either"></a>
|
|
<dt><pre><a href="op.html#Either"><span class="Identifier">Either</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">;</span> <span class="Identifier">B</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span>
|
|
<span class="Keyword">case</span> <span class="Identifier">isA</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span>
|
|
<span class="Keyword">of</span> <span class="Identifier">true</span><span class="Other">:</span>
|
|
<span class="Identifier">a</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">A</span>
|
|
|
|
<span class="Keyword">of</span> <span class="Identifier">false</span><span class="Other">:</span>
|
|
<span class="Identifier">b</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">B</span>
|
|
|
|
</pre></dt>
|
|
<dd>
|
|
|
|
An <tt class="docutils literal"><span class="pre">Either</span></tt> object can hold either one value or the other, but never both
|
|
|
|
</dd>
|
|
<a id="OP"></a>
|
|
<dt><pre><a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <a href="op.html#Either"><span class="Identifier">Either</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">,</span> <span class="Identifier">string</span><span class="Other">]</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Object to wrap the result of an operation. Alias of <tt class="docutils literal"><span class="pre">Either</span></tt> with a string as error message</p>
|
|
<p>The type is discriminated by the <tt class="docutils literal"><span class="pre">isOK</span></tt> bool. So it is an compiler error to try to access the value without checking if the operation was successful.</p>
|
|
<ul class="simple"><li><tt class="docutils literal"><span class="pre">isOk</span></tt>: Indicates if the operation was successful</li>
|
|
<li><tt class="docutils literal"><span class="pre">val</span></tt>: If successful, this will hold the real result value</li>
|
|
<li><tt class="docutils literal"><span class="pre">error</span></tt>: Otherwise this will hold an error message</li>
|
|
</ul>
|
|
|
|
|
|
</dd>
|
|
|
|
</dl></div>
|
|
<div class="section" id="18">
|
|
<h1><a class="toc-backref" href="#18">Templates</a></h1>
|
|
<dl class="item">
|
|
<a id="checkA.t,Either"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#checkA.t%2CEither"><span class="Identifier">checkA</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="op.html#Either"><span class="Identifier">Either</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
<a id="getA.t,Either[A,B]"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#getA.t%2CEither%5BA%2CB%5D"><span class="Identifier">getA</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">;</span> <span class="Identifier">B</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="op.html#Either"><span class="Identifier">Either</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">,</span> <span class="Identifier">B</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">A</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
<a id="getB.t,Either[A,B]"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#getB.t%2CEither%5BA%2CB%5D"><span class="Identifier">getB</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">;</span> <span class="Identifier">B</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="op.html#Either"><span class="Identifier">Either</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">,</span> <span class="Identifier">B</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">B</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
<a id="isOK.t,OP"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#isOK.t%2COP"><span class="Identifier">isOK</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
<a id="val.t,OP"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#val.t%2COP"><span class="Identifier">val</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
<a id="error.t,OP"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#error.t%2COP"><span class="Identifier">error</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
<a id="ok.t,T"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#ok.t%2CT"><span class="Identifier">ok</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">val</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
|
|
<dd>
|
|
|
|
Wraps the given value in a successful operation result.
|
|
|
|
</dd>
|
|
<a id="ok.t,OP[T],T"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#ok.t%2COP%5BT%5D%2CT"><span class="Identifier">ok</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">val</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
Set the result to the given value
|
|
|
|
</dd>
|
|
<a id="fail.t,,string"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#fail.t%2C%2Cstring"><span class="Identifier">fail</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">;</span> <span class="Other">]</span><span class="Other">(</span><span class="Identifier">O</span><span class="Other">:</span> <span class="Keyword">type</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">msg</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">O:type</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Will create a new operation result with the given error message. The type for the operation result is given explicitly.</p>
|
|
<p><strong>See Also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#fail,OP,string">fail proc</a></li>
|
|
<li><a class="reference external" href="#fail.t,static[string]">fail template</a></li>
|
|
</ul>
|
|
|
|
|
|
</dd>
|
|
<a id="fail.t,typedesc,string"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#fail.t%2Ctypedesc%2Cstring"><span class="Identifier">fail</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">;</span> <span class="Identifier">msg</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Will create a new operation result with the given error message. The type for the operation result is given explicitly.</p>
|
|
<p><strong>See Also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#fail,OP,string">fail proc</a></li>
|
|
<li><a class="reference external" href="#fail.t,static[string]">fail template</a></li>
|
|
</ul>
|
|
|
|
|
|
</dd>
|
|
<a id="fail.t,OP,string"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#fail.t%2COP%2Cstring"><span class="Identifier">fail</span></a><span class="Other">(</span><span class="Identifier">op</span><span class="Other">:</span> <a href="op.html#OP"><span class="Identifier">OP</span></a><span class="Other">;</span> <span class="Identifier">msg</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">OP</span></pre></dt>
|
|
<dd>
|
|
|
|
Will create a new operation result with the given error message. The type for the operation result is taken from the <tt class="docutils literal"><span class="pre">op</span></tt> argument.
|
|
<p><strong class="examples_text">Examples:</strong></p>
|
|
<pre class="listing"><span class="Keyword">proc</span> <span class="Identifier">someProc</span><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">OP</span><span class="Other">[</span><span class="Identifier">int</span><span class="Other">]</span> <span class="Other">=</span>
|
|
<span class="Identifier">result</span><span class="Other">.</span><span class="Identifier">fail</span> <span class="StringLit">"Not implemented!"</span>
|
|
|
|
<span class="Keyword">let</span> <span class="Identifier">data</span> <span class="Other">=</span> <span class="Identifier">someProc</span><span class="Other">(</span><span class="Other">)</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">data</span><span class="Other">.</span><span class="Identifier">isOk</span> <span class="Operator">==</span> <span class="Identifier">false</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">data</span><span class="Other">.</span><span class="Identifier">error</span> <span class="Operator">==</span> <span class="StringLit">"Not implemented!"</span></pre>
|
|
|
|
</dd>
|
|
<a id="fail.t,static[string]"></a>
|
|
<dt><pre><span class="Keyword">template</span> <a href="#fail.t%2Cstatic%5Bstring%5D"><span class="Identifier">fail</span></a><span class="Other">(</span><span class="Identifier">msg</span><span class="Other">:</span> <span class="Identifier">static</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
</dl></div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="twelve-columns footer">
|
|
<span class="nim-sprite"></span>
|
|
<br/>
|
|
<small style="color: var(--hint);">Made with Nim. Generated: 2020-07-07 13:52:22 UTC</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|