mirror of
https://github.com/bspeice/bspeice.github.io
synced 2024-10-10 20:21:30 -04:00
Update for new post
This commit is contained in:
parent
ee2b49ae0a
commit
3338b5b0ad
@ -4,22 +4,20 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="I listen to a lot of Drum and Bass music, because it's beautiful music. And there's a particular site, Bassdrive.com that hosts a lot of great content. Specifically, the archives section of the ...">
|
||||
<meta name="description" content="I listen to a lot of Drum and Bass music, because it's beautiful music. And there's a particular site, Bassdrive.com that hosts a lot of great content. Specifically, the archives section of the...">
|
||||
<meta name="keywords" content="nutone, Rust">
|
||||
<link rel="icon" href="https://bspeice.github.io/favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
|
||||
<title>A Rustic Re-Podcasting Server (Part 1) - Bradlee Speice</title>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://bspeice.github.io/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/pygment.css" rel="stylesheet">
|
||||
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="/theme/css/pygment.css" rel="stylesheet">
|
||||
<!-- /Stylesheets -->
|
||||
|
||||
<!-- RSS Feeds -->
|
||||
<link href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Bradlee Speice Full Atom Feed" />
|
||||
<link href="https://bspeice.github.io/feeds/blog.atom.xml" type="application/atom+xml" rel="alternate" title="Bradlee Speice Categories Atom Feed" />
|
||||
<!-- /RSS Feeds -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
@ -28,17 +26,6 @@
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-74711362-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- /Google Analytics -->
|
||||
|
||||
|
||||
</head>
|
||||
@ -52,7 +39,7 @@
|
||||
<div class="container">
|
||||
<div class="header-nav">
|
||||
<div class="header-logo">
|
||||
<a class="pull-left" href="https://bspeice.github.io/"><img class="mr20" src="https://bspeice.github.io/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
<a class="pull-left" href="/"><img class="mr20" src="/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
</div>
|
||||
<div class="nav pull-right">
|
||||
</div>
|
||||
@ -67,12 +54,12 @@
|
||||
<div class="col-lg-12">
|
||||
<div class="header-content">
|
||||
<h1 class="header-title">A Rustic Re-Podcasting Server (Part 1)</h1>
|
||||
<p class="header-date"> <a href="https://bspeice.github.io/author/bradlee-speice.html">Bradlee Speice</a>, Sat 22 October 2016, <a href="https://bspeice.github.io/category/blog.html">Blog</a></p>
|
||||
<p class="header-date"> <a href="/author/bradlee-speice.html">Bradlee Speice</a>, Sat 22 October 2016, <a href="/category/blog.html">Blog</a></p>
|
||||
<div class="header-underline"></div>
|
||||
<div class="clearfix"></div>
|
||||
<p class="pull-right header-tags">
|
||||
<span class="glyphicon glyphicon-tags mr5" aria-hidden="true"></span>
|
||||
<a href="https://bspeice.github.io/tag/nutone.html">nutone</a>, <a href="https://bspeice.github.io/tag/rust.html">Rust</a> </p>
|
||||
<a href="/tag/nutone.html">nutone</a>, <a href="/tag/rust.html">Rust</a> </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -128,15 +115,15 @@ on some bad cases, <code>str <-> bytes</code> specifically), but Rust is h
|
||||
should be incredibly simple: All I want is to echo back
|
||||
<code>Didn't find URL: <url></code>. Shouldn't be that hard right? In Python I'd just do
|
||||
something like:</p>
|
||||
<div class="highlight"><pre><span class="k">def</span> <span class="nf">echo_handler</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">echo_handler</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<span class="k">return</span> <span class="s2">"You're visiting: {}"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">uri</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>And we'd call it a day. Rust isn't so simple. Let's start with the trivial
|
||||
examples people post online:</p>
|
||||
<div class="highlight"><pre><span class="k">fn</span><span class="w"> </span><span class="n">hello_world</span><span class="p">(</span><span class="n">req</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="s">"You found the server!"</span><span class="p">)))</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="k">fn</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">req</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span>-> <span class="nc">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="s">"You found the server!"</span><span class="p">)))</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
@ -145,22 +132,22 @@ examples people post online:</p>
|
||||
version! All we need to do is just send back a string of some form. So, we
|
||||
look up the documentation for <a href="http://ironframework.io/doc/iron/request/struct.Request.html"><code>Request</code></a> and see a <code>url</code> field that will contain
|
||||
what we want. Let's try the first iteration:</p>
|
||||
<div class="highlight"><pre><span class="k">fn</span><span class="w"> </span><span class="n">hello_world</span><span class="p">(</span><span class="n">req</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="s">"You found the URL: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">req</span><span class="p">.</span><span class="n">url</span><span class="p">)))</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="k">fn</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">req</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span>-> <span class="nc">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="s">"You found the URL: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">req</span><span class="p">.</span><span class="n">url</span><span class="p">)))</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>Which yields the error:</p>
|
||||
<div class="highlight"><pre>error[E0369]: binary operation `+` cannot be applied to type `&'static str`
|
||||
<div class="highlight"><pre><span></span>error[E0369]: binary operation `+` cannot be applied to type `&'static str`
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>OK, what's going on here? Time to start Googling for <a href="https://www.google.com/#q=concatenate+strings+in+rust">"concatenate strings in Rust"</a>. That's what we
|
||||
want to do right? Concatenate a static string and the URL.</p>
|
||||
<p>After Googling, we come across a helpful <a href="https://doc.rust-lang.org/std/macro.concat!.html"><code>concat!</code></a> macro that looks really nice! Let's try that one:</p>
|
||||
<div class="highlight"><pre><span class="k">fn</span><span class="w"> </span><span class="n">hello_world</span><span class="p">(</span><span class="n">req</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="n">concat</span><span class="o">!</span><span class="p">(</span><span class="s">"You found the URL: "</span><span class="p">,</span><span class="w"> </span><span class="n">req</span><span class="p">.</span><span class="n">url</span><span class="p">))))</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="k">fn</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">req</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span>-> <span class="nc">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="n">concat</span><span class="o">!</span><span class="p">(</span><span class="s">"You found the URL: "</span><span class="p">,</span><span class="w"> </span><span class="n">req</span><span class="p">.</span><span class="n">url</span><span class="p">))))</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
@ -172,8 +159,8 @@ at compile time what <code>req.url</code> is. Which, in my outsider opinion, is
|
||||
strange. <code>println!</code> and <code>format!</code>, etc., all handle values they don't know at
|
||||
compile time. Why can't <code>concat!</code>? By any means, we need a new plan of attack.
|
||||
How about we try formatting strings?</p>
|
||||
<div class="highlight"><pre><span class="k">fn</span><span class="w"> </span><span class="n">hello_world</span><span class="p">(</span><span class="n">req</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">"You found the URL: {}"</span><span class="p">,</span><span class="w"> </span><span class="n">req</span><span class="p">.</span><span class="n">url</span><span class="p">))))</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="k">fn</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">req</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span>-> <span class="nc">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">"You found the URL: {}"</span><span class="p">,</span><span class="w"> </span><span class="n">req</span><span class="p">.</span><span class="n">url</span><span class="p">))))</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
@ -204,9 +191,9 @@ working on things that are a bit more complex?</p>
|
||||
<p>We're going to cover that here. Our first try: creating a function which returns
|
||||
other functions. This is a principle called <a href="http://stackoverflow.com/a/36321/1454178">currying</a>. We set up a function that allows us to keep some data in scope
|
||||
for another function to come later.</p>
|
||||
<div class="highlight"><pre><span class="k">fn</span><span class="w"> </span><span class="n">build_handler</span><span class="p">(</span><span class="n">message</span><span class="o">:</span><span class="w"> </span><span class="nb">String</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="n">move</span><span class="w"> </span><span class="o">|</span><span class="n">_</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="n">message</span><span class="p">)))</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="k">fn</span> <span class="nf">build_handler</span><span class="p">(</span><span class="n">message</span>: <span class="nb">String</span><span class="p">)</span><span class="w"> </span>-> <span class="nb">Fn</span><span class="p">(</span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span>-> <span class="nc">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="k">move</span><span class="w"> </span><span class="o">|</span><span class="n">_</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="n">message</span><span class="p">)))</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
</pre></div>
|
||||
@ -215,7 +202,7 @@ for another function to come later.</p>
|
||||
<p>We've simply set up a function that returns another anonymous function with the
|
||||
<code>message</code> parameter scoped in. If you compile this, you get not 1, not 2, but 5
|
||||
new errors. 4 of them are the same though:</p>
|
||||
<div class="highlight"><pre>error[E0277]: the trait bound `for<'r, 'r, 'r> std::ops::Fn(&'r mut iron::Request<'r, 'r>) -> std::result::Result<iron::Response, iron::IronError> + 'static: std::marker::Sized` is not satisfied
|
||||
<div class="highlight"><pre><span></span>error[E0277]: the trait bound `for<'r, 'r, 'r> std::ops::Fn(&'r mut iron::Request<'r, 'r>) -> std::result::Result<iron::Response, iron::IronError> + 'static: std::marker::Sized` is not satisfied
|
||||
</pre></div>
|
||||
|
||||
|
||||
@ -243,19 +230,19 @@ we've been working with so far.</p>
|
||||
<p>The principle is that we need to define a new <code>struct</code> to hold our data, then
|
||||
implement that <code>handle()</code> method to return the result. Something that looks
|
||||
like this might do:</p>
|
||||
<div class="highlight"><pre><span class="k">struct</span><span class="w"> </span><span class="n">EchoHandler</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="n">message</span><span class="o">:</span><span class="w"> </span><span class="nb">String</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="k">struct</span> <span class="nc">EchoHandler</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="n">message</span>: <span class="nb">String</span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
|
||||
<span class="k">impl</span><span class="w"> </span><span class="n">Handler</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">EchoHandler</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">handle</span><span class="p">(</span><span class="o">&</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">message</span><span class="p">)))</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="k">fn</span> <span class="nf">handle</span><span class="p">(</span><span class="o">&</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">_</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="p">)</span><span class="w"> </span>-> <span class="nc">IronResult</span><span class="o"><</span><span class="n">Response</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">message</span><span class="p">)))</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
|
||||
<span class="c1">// Later in the code when we set up the router...</span>
|
||||
<span class="kd">let</span><span class="w"> </span><span class="n">echo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">EchoHandler</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="n">message</span><span class="o">:</span><span class="w"> </span><span class="s">"Is it working yet?"</span><span class="w"></span>
|
||||
<span class="w"> </span><span class="n">message</span>: <span class="s">"Is it working yet?"</span><span class="w"></span>
|
||||
<span class="p">}</span><span class="w"></span>
|
||||
<span class="n">router</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"/"</span><span class="p">,</span><span class="w"> </span><span class="n">echo</span><span class="p">.</span><span class="n">handle</span><span class="p">,</span><span class="w"> </span><span class="s">"index"</span><span class="p">);</span><span class="w"></span>
|
||||
</pre></div>
|
||||
@ -264,38 +251,38 @@ like this might do:</p>
|
||||
<p>We attempt to build a struct, and give its <code>handle</code> method off to the router
|
||||
so the router knows what to do.</p>
|
||||
<p>You guessed it, more errors:</p>
|
||||
<div class="highlight"><pre><span class="n">error</span><span class="o">:</span> <span class="n">attempted</span> <span class="n">to</span> <span class="n">take</span> <span class="n">value</span> <span class="n">of</span> <span class="n">method</span> <span class="err">`</span><span class="n">handle</span><span class="err">`</span> <span class="n">on</span> <span class="n">type</span> <span class="err">`</span><span class="n">EchoHandler</span><span class="err">`</span>
|
||||
<div class="highlight"><pre><span></span><span class="n">error</span><span class="o">:</span> <span class="n">attempted</span> <span class="n">to</span> <span class="n">take</span> <span class="n">value</span> <span class="n">of</span> <span class="n">method</span> <span class="err">`</span><span class="n">handle</span><span class="err">`</span> <span class="n">on</span> <span class="n">type</span> <span class="err">`</span><span class="n">EchoHandler</span><span class="err">`</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>Now, the Rust compiler is actually a really nice fellow, and offers us help:</p>
|
||||
<div class="highlight"><pre><span class="n">help</span><span class="o">:</span> <span class="n">maybe</span> <span class="n">a</span> <span class="err">`</span><span class="o">()</span><span class="err">`</span> <span class="n">to</span> <span class="n">call</span> <span class="n">it</span> <span class="k">is</span> <span class="n">missing</span><span class="o">?</span> <span class="n">If</span> <span class="n">not</span><span class="o">,</span> <span class="k">try</span> <span class="n">an</span> <span class="n">anonymous</span> <span class="kd">function</span>
|
||||
<div class="highlight"><pre><span></span><span class="n">help</span><span class="o">:</span> <span class="n">maybe</span> <span class="n">a</span> <span class="err">`</span><span class="o">()</span><span class="err">`</span> <span class="n">to</span> <span class="n">call</span> <span class="n">it</span> <span class="k">is</span> <span class="n">missing</span><span class="o">?</span> <span class="n">If</span> <span class="n">not</span><span class="o">,</span> <span class="k">try</span> <span class="n">an</span> <span class="n">anonymous</span> <span class="kd">function</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>We definitely don't want to call that function, so maybe try an anonymous
|
||||
function as it recommends?</p>
|
||||
<div class="highlight"><pre><span class="n">router</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"/"</span><span class="p">,</span><span class="w"> </span><span class="o">|</span><span class="n">req</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="o">|</span><span class="w"> </span><span class="n">echo</span><span class="p">.</span><span class="n">handle</span><span class="p">(</span><span class="n">req</span><span class="p">),</span><span class="w"> </span><span class="s">"index"</span><span class="p">);</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="n">router</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"/"</span><span class="p">,</span><span class="w"> </span><span class="o">|</span><span class="n">req</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="o">|</span><span class="w"> </span><span class="n">echo</span><span class="p">.</span><span class="n">handle</span><span class="p">(</span><span class="n">req</span><span class="p">),</span><span class="w"> </span><span class="s">"index"</span><span class="p">);</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>Another error:</p>
|
||||
<div class="highlight"><pre>error[E0373]: closure may outlive the current function, but it borrows `echo`, which is owned by the current function
|
||||
<div class="highlight"><pre><span></span>error[E0373]: closure may outlive the current function, but it borrows `echo`, which is owned by the current function
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>Another helpful message:</p>
|
||||
<div class="highlight"><pre><span class="n">help</span><span class="o">:</span> <span class="n">to</span> <span class="n">force</span> <span class="n">the</span> <span class="n">closure</span> <span class="n">to</span> <span class="n">take</span> <span class="n">ownership</span> <span class="n">of</span> <span class="err">`</span><span class="n">echo</span><span class="err">`</span> <span class="o">(</span><span class="n">and</span> <span class="n">any</span> <span class="n">other</span> <span class="n">referenced</span> <span class="n">variables</span><span class="o">),</span> <span class="n">use</span> <span class="n">the</span> <span class="err">`</span><span class="n">move</span><span class="err">`</span> <span class="n">keyword</span>
|
||||
<div class="highlight"><pre><span></span><span class="n">help</span><span class="o">:</span> <span class="n">to</span> <span class="n">force</span> <span class="n">the</span> <span class="n">closure</span> <span class="n">to</span> <span class="n">take</span> <span class="n">ownership</span> <span class="n">of</span> <span class="err">`</span><span class="n">echo</span><span class="err">`</span> <span class="o">(</span><span class="n">and</span> <span class="n">any</span> <span class="n">other</span> <span class="n">referenced</span> <span class="n">variables</span><span class="o">),</span> <span class="n">use</span> <span class="n">the</span> <span class="err">`</span><span class="n">move</span><span class="err">`</span> <span class="n">keyword</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>We're getting closer though! Let's implement this change:</p>
|
||||
<div class="highlight"><pre><span class="n">router</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"/"</span><span class="p">,</span><span class="w"> </span><span class="n">move</span><span class="w"> </span><span class="o">|</span><span class="n">req</span><span class="o">:</span><span class="w"> </span><span class="o">&</span><span class="k">mut</span><span class="w"> </span><span class="n">Request</span><span class="o">|</span><span class="w"> </span><span class="n">echo</span><span class="p">.</span><span class="n">handle</span><span class="p">(</span><span class="n">req</span><span class="p">),</span><span class="w"> </span><span class="s">"index"</span><span class="p">);</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="n">router</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"/"</span><span class="p">,</span><span class="w"> </span><span class="k">move</span><span class="w"> </span><span class="o">|</span><span class="n">req</span>: <span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Request</span><span class="o">|</span><span class="w"> </span><span class="n">echo</span><span class="p">.</span><span class="n">handle</span><span class="p">(</span><span class="n">req</span><span class="p">),</span><span class="w"> </span><span class="s">"index"</span><span class="p">);</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>And here's where things get strange:</p>
|
||||
<div class="highlight"><pre>error[E0507]: cannot move out of borrowed content
|
||||
<div class="highlight"><pre><span></span>error[E0507]: cannot move out of borrowed content
|
||||
--> src/main.rs:18:40
|
||||
|
|
||||
18 | Ok(Response::with((status::Ok, self.message)))
|
||||
@ -320,7 +307,7 @@ instead of transferring ownership</li>
|
||||
audience out. Because <code>iron</code> won't accept a reference, we are forced into the
|
||||
second option: making a copy. To do so, we just need to change the function
|
||||
to look like this:</p>
|
||||
<div class="highlight"><pre><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span><span class="o">::</span><span class="n">with</span><span class="p">((</span><span class="n">status</span><span class="o">::</span><span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">message</span><span class="p">.</span><span class="n">clone</span><span class="p">())))</span><span class="w"></span>
|
||||
<div class="highlight"><pre><span></span><span class="nb">Ok</span><span class="p">(</span><span class="n">Response</span>::<span class="n">with</span><span class="p">((</span><span class="n">status</span>::<span class="nb">Ok</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">message</span><span class="p">.</span><span class="n">clone</span><span class="p">())))</span><span class="w"></span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
@ -356,20 +343,6 @@ incredibly precise about how I use it.</p>
|
||||
going to take me a lot longer to do this than I originally thought.</p>
|
||||
|
||||
|
||||
<div class="comments">
|
||||
<div id="disqus_thread"></div>
|
||||
<script type="text/javascript">
|
||||
var disqus_shortname = 'bradleespeice';
|
||||
var disqus_identifier = 'a-rustic-re-podcasting-server-part-1.html';
|
||||
var disqus_url = 'https://bspeice.github.io/a-rustic-re-podcasting-server-part-1.html';
|
||||
(function() {
|
||||
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
|
||||
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
|
||||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
||||
})();
|
||||
</script>
|
||||
<noscript>Please enable JavaScript to view the comments.</noscript>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- /Content -->
|
||||
@ -381,7 +354,6 @@ going to take me a lot longer to do this than I originally thought.</p>
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
<div class="footer-title"></div>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
|
@ -6,19 +6,18 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="keywords" content="">
|
||||
<link rel="icon" href="https://bspeice.github.io/favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
|
||||
<title> - Bradlee Speice</title>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://bspeice.github.io/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/pygment.css" rel="stylesheet">
|
||||
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="/theme/css/pygment.css" rel="stylesheet">
|
||||
<!-- /Stylesheets -->
|
||||
|
||||
<!-- RSS Feeds -->
|
||||
<link href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Bradlee Speice Full Atom Feed" />
|
||||
<!-- /RSS Feeds -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
@ -27,17 +26,6 @@
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-74711362-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- /Google Analytics -->
|
||||
|
||||
|
||||
</head>
|
||||
@ -51,7 +39,7 @@
|
||||
<div class="container">
|
||||
<div class="header-nav">
|
||||
<div class="header-logo">
|
||||
<a class="pull-left" href="https://bspeice.github.io/"><img class="mr20" src="https://bspeice.github.io/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
<a class="pull-left" href="/"><img class="mr20" src="/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
</div>
|
||||
<div class="nav pull-right">
|
||||
</div>
|
||||
@ -80,36 +68,38 @@
|
||||
<!-- Content -->
|
||||
<div class="archive-container">
|
||||
<div class="container content archive">
|
||||
<h2><a href="https://bspeice.github.io/archives.html"></a></h2>
|
||||
<h2><a href="/archives.html"></a></h2>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>Tue 16 January 2018</dt>
|
||||
<dd><a href="/captains-cookbook-part-1.html">Captain's Cookbook - Part 1</a></dd>
|
||||
<dt>Tue 01 November 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dd><a href="/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dt>Sat 22 October 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dd><a href="/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dt>Wed 08 June 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dd><a href="/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dt>Sun 15 May 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dd><a href="/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dt>Wed 06 April 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dd><a href="/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dt>Mon 28 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dd><a href="/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dt>Sat 05 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dd><a href="/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dt>Fri 26 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dd><a href="/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dt>Wed 03 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dd><a href="/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dt>Sat 23 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dd><a href="/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dt>Fri 01 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dd><a href="/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dt>Sat 26 December 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dd><a href="/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dt>Fri 27 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dd><a href="/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dt>Thu 19 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
<dd><a href="/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@ -122,7 +112,6 @@
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
<div class="footer-title"></div>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
|
File diff suppressed because one or more lines are too long
@ -6,19 +6,18 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content=" Bradlee Speice">
|
||||
<meta name="keywords" content="">
|
||||
<link rel="icon" href="https://bspeice.github.io/favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
|
||||
<title> Bradlee Speice - Bradlee Speice</title>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://bspeice.github.io/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/pygment.css" rel="stylesheet">
|
||||
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="/theme/css/pygment.css" rel="stylesheet">
|
||||
<!-- /Stylesheets -->
|
||||
|
||||
<!-- RSS Feeds -->
|
||||
<link href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Bradlee Speice Full Atom Feed" />
|
||||
<!-- /RSS Feeds -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
@ -27,17 +26,6 @@
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-74711362-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- /Google Analytics -->
|
||||
|
||||
|
||||
</head>
|
||||
@ -51,7 +39,7 @@
|
||||
<div class="container">
|
||||
<div class="header-nav">
|
||||
<div class="header-logo">
|
||||
<a class="pull-left" href="https://bspeice.github.io/"><img class="mr20" src="https://bspeice.github.io/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
<a class="pull-left" href="/"><img class="mr20" src="/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
</div>
|
||||
<div class="nav pull-right">
|
||||
</div>
|
||||
@ -80,36 +68,38 @@
|
||||
<!-- Content -->
|
||||
<div class="archive-container">
|
||||
<div class="container content archive">
|
||||
<h2><a href="https://bspeice.github.io/author/bradlee-speice.html"></a></h2>
|
||||
<h2><a href="/author/bradlee-speice.html"></a></h2>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>Tue 16 January 2018</dt>
|
||||
<dd><a href="/captains-cookbook-part-1.html">Captain's Cookbook - Part 1</a></dd>
|
||||
<dt>Tue 01 November 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dd><a href="/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dt>Sat 22 October 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dd><a href="/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dt>Wed 08 June 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dd><a href="/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dt>Sun 15 May 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dd><a href="/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dt>Wed 06 April 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dd><a href="/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dt>Mon 28 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dd><a href="/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dt>Sat 05 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dd><a href="/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dt>Fri 26 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dd><a href="/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dt>Wed 03 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dd><a href="/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dt>Sat 23 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dd><a href="/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dt>Fri 01 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dd><a href="/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dt>Sat 26 December 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dd><a href="/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dt>Fri 27 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dd><a href="/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dt>Thu 19 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
<dd><a href="/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@ -122,7 +112,6 @@
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
<div class="footer-title"></div>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
|
@ -6,19 +6,18 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content=" Bradlee Speice">
|
||||
<meta name="keywords" content="">
|
||||
<link rel="icon" href="https://bspeice.github.io/favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
|
||||
<title> Bradlee Speice - Bradlee Speice</title>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://bspeice.github.io/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/pygment.css" rel="stylesheet">
|
||||
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="/theme/css/pygment.css" rel="stylesheet">
|
||||
<!-- /Stylesheets -->
|
||||
|
||||
<!-- RSS Feeds -->
|
||||
<link href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Bradlee Speice Full Atom Feed" />
|
||||
<!-- /RSS Feeds -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
@ -27,17 +26,6 @@
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-74711362-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- /Google Analytics -->
|
||||
|
||||
|
||||
</head>
|
||||
@ -51,7 +39,7 @@
|
||||
<div class="container">
|
||||
<div class="header-nav">
|
||||
<div class="header-logo">
|
||||
<a class="pull-left" href="https://bspeice.github.io/"><img class="mr20" src="https://bspeice.github.io/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
<a class="pull-left" href="/"><img class="mr20" src="/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
</div>
|
||||
<div class="nav pull-right">
|
||||
</div>
|
||||
@ -80,36 +68,38 @@
|
||||
<!-- Content -->
|
||||
<div class="archive-container">
|
||||
<div class="container content archive">
|
||||
<h2><a href="https://bspeice.github.io/author/bradlee-speice.html"></a></h2>
|
||||
<h2><a href="/author/bradlee-speice.html"></a></h2>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>Tue 16 January 2018</dt>
|
||||
<dd><a href="/captains-cookbook-part-1.html">Captain's Cookbook - Part 1</a></dd>
|
||||
<dt>Tue 01 November 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dd><a href="/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dt>Sat 22 October 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dd><a href="/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dt>Wed 08 June 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dd><a href="/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dt>Sun 15 May 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dd><a href="/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dt>Wed 06 April 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dd><a href="/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dt>Mon 28 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dd><a href="/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dt>Sat 05 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dd><a href="/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dt>Fri 26 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dd><a href="/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dt>Wed 03 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dd><a href="/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dt>Sat 23 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dd><a href="/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dt>Fri 01 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dd><a href="/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dt>Sat 26 December 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dd><a href="/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dt>Fri 27 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dd><a href="/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dt>Thu 19 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
<dd><a href="/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@ -122,7 +112,6 @@
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
<div class="footer-title"></div>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
|
57
authors.html
57
authors.html
@ -6,19 +6,18 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="keywords" content="">
|
||||
<link rel="icon" href="https://bspeice.github.io/favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
|
||||
<title> - Bradlee Speice</title>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://bspeice.github.io/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="https://bspeice.github.io/theme/css/pygment.css" rel="stylesheet">
|
||||
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="/theme/css/pygment.css" rel="stylesheet">
|
||||
<!-- /Stylesheets -->
|
||||
|
||||
<!-- RSS Feeds -->
|
||||
<link href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Bradlee Speice Full Atom Feed" />
|
||||
<!-- /RSS Feeds -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
@ -27,17 +26,6 @@
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-74711362-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- /Google Analytics -->
|
||||
|
||||
|
||||
</head>
|
||||
@ -51,7 +39,7 @@
|
||||
<div class="container">
|
||||
<div class="header-nav">
|
||||
<div class="header-logo">
|
||||
<a class="pull-left" href="https://bspeice.github.io/"><img class="mr20" src="https://bspeice.github.io/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
<a class="pull-left" href="/"><img class="mr20" src="/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
</div>
|
||||
<div class="nav pull-right">
|
||||
</div>
|
||||
@ -80,36 +68,38 @@
|
||||
<!-- Content -->
|
||||
<div class="archive-container">
|
||||
<div class="container content archive">
|
||||
<h2><a href="https://bspeice.github.io/author/bradlee-speice.html">Bradlee Speice</a></h2>
|
||||
<h2><a href="/author/bradlee-speice.html">Bradlee Speice</a></h2>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>Tue 16 January 2018</dt>
|
||||
<dd><a href="/captains-cookbook-part-1.html">Captain's Cookbook - Part 1</a></dd>
|
||||
<dt>Tue 01 November 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dd><a href="/audio-compression-using-pca.html">Audio Compression using PCA</a></dd>
|
||||
<dt>Sat 22 October 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dd><a href="/a-rustic-re-podcasting-server-part-1.html">A Rustic Re-Podcasting Server (Part 1)</a></dd>
|
||||
<dt>Wed 08 June 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dd><a href="/event-studies-and-earnings-releases.html">Event Studies and Earnings Releases</a></dd>
|
||||
<dt>Sun 15 May 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dd><a href="/the-unfair-casino.html">The Unfair Casino</a></dd>
|
||||
<dt>Wed 06 April 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dd><a href="/tick-tock.html">Tick Tock...</a></dd>
|
||||
<dt>Mon 28 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dd><a href="/tweet-like-me.html">Tweet Like Me</a></dd>
|
||||
<dt>Sat 05 March 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dd><a href="/predicting-santander-customer-happiness.html">Predicting Santander Customer Happiness</a></dd>
|
||||
<dt>Fri 26 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dd><a href="/profitability-using-the-investment-formula.html">Profitability using the Investment Formula</a></dd>
|
||||
<dt>Wed 03 February 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dd><a href="/guaranteed-money-maker.html">Guaranteed Money Maker</a></dd>
|
||||
<dt>Sat 23 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dd><a href="/cloudy-in-seattle.html">Cloudy in Seattle</a></dd>
|
||||
<dt>Fri 01 January 2016</dt>
|
||||
<dd><a href="https://bspeice.github.io/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dd><a href="/complaining-about-the-weather.html">Complaining about the Weather</a></dd>
|
||||
<dt>Sat 26 December 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dd><a href="/testing-cramer.html">Testing Cramer</a></dd>
|
||||
<dt>Fri 27 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dd><a href="/autocallable-bonds.html">Autocallable Bonds</a></dd>
|
||||
<dt>Thu 19 November 2015</dt>
|
||||
<dd><a href="https://bspeice.github.io/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
<dd><a href="/welcome-and-an-algorithm.html">Welcome, and an algorithm</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@ -122,7 +112,6 @@
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
<div class="footer-title"></div>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://bspeice.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
|
||||
|
File diff suppressed because one or more lines are too long
313
captains-cookbook-part-1.html
Normal file
313
captains-cookbook-part-1.html
Normal file
@ -0,0 +1,313 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="Captain's Cookbook - Part 1 I've been working a lot with Cap'N Proto recently with Rust, but there's a real dearth of information on how to set up and get going quickly. In the interest of trying...">
|
||||
<meta name="keywords" content="capnproto rust">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
|
||||
<title>Captain's Cookbook - Part 1 - Bradlee Speice</title>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/theme/css/fonts.css" rel="stylesheet">
|
||||
<link href="/theme/css/nest.css" rel="stylesheet">
|
||||
<link href="/theme/css/pygment.css" rel="stylesheet">
|
||||
<!-- /Stylesheets -->
|
||||
|
||||
<!-- RSS Feeds -->
|
||||
<!-- /RSS Feeds -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- Header -->
|
||||
<div class="header-container gradient">
|
||||
|
||||
<!-- Static navbar -->
|
||||
<div class="container">
|
||||
<div class="header-nav">
|
||||
<div class="header-logo">
|
||||
<a class="pull-left" href="/"><img class="mr20" src="/images/logo.svg" alt="logo">Bradlee Speice</a>
|
||||
</div>
|
||||
<div class="nav pull-right">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /Static navbar -->
|
||||
|
||||
<!-- Header -->
|
||||
<!-- Header -->
|
||||
<div class="container header-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="header-content">
|
||||
<h1 class="header-title">Captain's Cookbook - Part 1</h1>
|
||||
<p class="header-date"> <a href="/author/bradlee-speice.html">Bradlee Speice</a>, Tue 16 January 2018, <a href="/category/blog.html">Blog</a></p>
|
||||
<div class="header-underline"></div>
|
||||
<div class="clearfix"></div>
|
||||
<p class="pull-right header-tags">
|
||||
<span class="glyphicon glyphicon-tags mr5" aria-hidden="true"></span>
|
||||
<a href="/tag/capnproto-rust.html">capnproto rust</a> </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /Header -->
|
||||
<!-- /Header -->
|
||||
|
||||
</div>
|
||||
<!-- /Header -->
|
||||
|
||||
|
||||
<!-- Content -->
|
||||
<div class="container content">
|
||||
<h1>Captain's Cookbook - Part 1</h1>
|
||||
<p>I've been working a lot with <a href="https://capnproto.org/">Cap'N Proto</a> recently with Rust, but there's a real dearth of information
|
||||
on how to set up and get going quickly. In the interest of trying to get more people using this (because I think it's
|
||||
fantastic), I'm going to work through a couple of examples detailing what exactly should be done to get going.</p>
|
||||
<p>So, what is Cap'N Proto? It's a data serialization library. It has contemporaries with <a href="https://developers.google.com/protocol-buffers/">Protobuf</a>
|
||||
and <a href="https://google.github.io/flatbuffers/">FlatBuffers</a>, but is better compared with FlatBuffers. The whole point behind it
|
||||
is to define a schema language and serialization format such that:</p>
|
||||
<ol>
|
||||
<li>Applications that do not share the same base programming language can communicate</li>
|
||||
<li>The data and schema you use can naturally evolve over time as your needs change</li>
|
||||
</ol>
|
||||
<p>Accompanying this are typically code generators that take the schemas you define for your application and give you back
|
||||
code for different languages to get data to and from that schema.</p>
|
||||
<p>Now, what makes Cap'N Proto different from, say, Protobuf, is that there is no serialization/deserialization step the same way
|
||||
as is implemented with Protobuf. Instead, the idea is that the message itself can be loaded in memory and used directly there.</p>
|
||||
<p>We're going to take a look at a series of progressively more complex projects that use Cap'N Proto in an effort to provide some
|
||||
examples of what idiomatic usage looks like, and shorten the startup time needed to make use of this library in Rust projects.
|
||||
If you want to follow along, feel free. If not, I've posted <a href="https://github.com/bspeice/capnp_cookbook_1">the final result</a>
|
||||
for reference.</p>
|
||||
<h1>Step 1: Installing <code>capnp</code></h1>
|
||||
<p>The <code>capnp</code> binary itself is needed for taking the schema files you write and turning them into a format that can be used by the
|
||||
code generation libraries. Don't ask me what that actually means, I just know that you need to make sure this is installed.</p>
|
||||
<p>I'll refer you to <a href="https://capnproto.org/install.html">Cap'N Proto's installation instructions</a> here. As a quick TLDR though:</p>
|
||||
<ul>
|
||||
<li>Linux users will likely have a binary shipped by their package manager - On Ubuntu, <code>apt install capnproto</code> is enough</li>
|
||||
<li>OS X users can use <a href="https://brew.sh/">Homebrew</a> as an easy install path. Just <code>brew install capnp</code></li>
|
||||
<li>Windows users are a bit more complicated. If you're using <a href="https://chocolatey.org/">Chocolatey</a>, there's <a href="https://chocolatey.org/packages/capnproto/">a package</a> available. If that doesn't work however, you need to download <a href="https://capnproto.org/capnproto-c++-win32-0.6.1.zip">a release zip</a> and make sure that the <code>capnp.exe</code> binary is in your <code>%PATH%</code> environment variable</li>
|
||||
</ul>
|
||||
<p>The way you know you're done with this step is if the following command works in your shell:</p>
|
||||
<div class="highlight"><pre><span></span>capnp id
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h1>Step 2: Starting a Cap'N Proto Rust project</h1>
|
||||
<p>After the <code>capnp</code> binary is set up, it's time to actually create our Rust project. Nothing terribly complex here, just a simple</p>
|
||||
<div class="highlight"><pre><span></span>mkdir capnp_cookbook_1
|
||||
<span class="nb">cd</span> capnp_cookbook_1
|
||||
cargo init --bin
|
||||
</pre></div>
|
||||
|
||||
|
||||
<p>We'll put the following content into <code>Cargo.toml</code>:</p>
|
||||
<div class="highlight"><pre><span></span><span class="k">[package]</span>
|
||||
<span class="na">name</span> <span class="o">=</span> <span class="s">"capnp_cookbook_1"</span>
|
||||
<span class="na">version</span> <span class="o">=</span> <span class="s">"0.1.0"</span>
|
||||
<span class="na">authors</span> <span class="o">=</span> <span class="s">["Bradlee Speice |