<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Preethi Kumar on Medium]]></title>
        <description><![CDATA[Stories by Preethi Kumar on Medium]]></description>
        <link>https://medium.com/@preethikumar?source=rss-282a72573069------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cs0Wejj9J39DuZ7KFsSIBw.jpeg</url>
            <title>Stories by Preethi Kumar on Medium</title>
            <link>https://medium.com/@preethikumar?source=rss-282a72573069------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:05:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@preethikumar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Moving to TCPStream, Bye Tokio!]]></title>
            <link>https://medium.com/adventures-in-rust/moving-to-tcpstream-bye-tokio-5a1488f337f6?source=rss-282a72573069------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a1488f337f6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[tokio]]></category>
            <dc:creator><![CDATA[Preethi Kumar]]></dc:creator>
            <pubDate>Thu, 13 Apr 2017 12:42:47 GMT</pubDate>
            <atom:updated>2019-08-29T19:16:23.479Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGxkKcM289IIglpQ6TMwdA.jpeg" /></figure><p>Hey people, the last time we wrote about our little web server project, we had built a simple static file server.</p><p>And you know, we were absolute newbies in Rust and were trying to get a hold of the ecosystem and the tooling while putting this together. Based on some quick research we found this promising networking library, <a href="https://tokio.rs/"><strong><em>Tokio</em></strong></a><strong><em>. </em></strong>And we thought we could use it as a base for our project.</p><p>As Tokio’s website puts it, Tokio is —</p><blockquote>A platform for writing fast networking code with Rust.</blockquote><p>It sure sounded like something we’d want to use for our learning project. We dug through the guides which were basically delivered using few example apps. The first example they introduced us to, <a href="https://tokio.rs/docs/getting-started/simple-server/">writing an echo server with Tokio</a>, really showed how Tokio would allow us to cleanly implement a network stack complete from handing requests and responses to the protocol that’s being employed as well.</p><p>We were very excited and managed to hack together a simple static file server. But then, at one point our productivity started dropping. We hit the brakes and thought about our decision to go with Tokio and finally decided to drop the idea and go with something else. Before we tell you about the replacement, here’s our pain points. Hopefully we can learn a lesson or two from this.</p><ol><li><strong><em>Hard time putting the abstractions to use — </em></strong>Since we were very new to Rust, we had a very hard time understanding the example code and reading through the docs and figuring out how to make Tokio’s abstractions work for us and where the boundaries lied. We basically ended up spending more time learning about these abstractions <em>(Codec, Protocol, Service, etc) </em>than building useful things over them.</li><li><strong><em>Navigating the samples and projects that use Tokio — </em></strong>Since we were absolutely new to Rust, navigating even a simple piece of code was a difficult endeavour. And when we tried to learn from a some projects on GitHub that used Tokio to build stuff, we ended up jumping back and forth between the code and the docs a little too often than we’d like and even though we eventually ended up liking the docs, they were not very intuitive in the beginning. Tokio required us to understand a little too much <em>(io, core, proto, service, futures, etc..) </em>and it ended up becoming overwhelming for us, fledgling Rust developers :)</li></ol><p>To put it short, even after a simple static file server that we referred in our <a href="https://medium.com/adventures-in-rust/peek-a-boo-rust-cc46dee79ae4">first post</a>, we still did not have a clear understanding of how things were wired together right from socket creation to how the response was being sent out. And this was a big problem for us as the whole point of this project is to help us learn the very basics of building a server.</p><p>I’m sure if we come back to this post a few months down the line, we’re going to be bashing our amateur-selves for dropping Tokio for these reasons ;)</p><p><strong>Enter Rust’s own std::net module</strong></p><p>With Tokio gone, we looked toward Rust’s std::net module. After going through the docs and few examples, we felt this is what we should have used in the first place.</p><p>Just take a look at this code —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25e2d21291b6977722b45ba62b321ab3/href">https://medium.com/media/25e2d21291b6977722b45ba62b321ab3/href</a></iframe><p>We had to spend a fraction of the time that we spent with Tokio in order to understand this and put these modules to use.</p><p>Here’s what we did next —</p><ol><li>We set up a basic server that simply responds with <em>Hello World. </em>Not very useful indeed, but always a good start.</li><li>Planned out the initial features that we want our web server to provide <br><em>1. Static File Serving <br>2. Support CGI Scripting <br>3. Reverse Proxying</em></li><li>Integrated a <a href="https://github.com/seanmonstar/httparse">HTTP Parser crate</a>.</li><li>Setup a very basic, temporary, hard-coded router.</li><li>Completed the static file server. (We’re <a href="https://github.com/PritiKumr/rust-httpd/issues/3">not able to serve PDFs</a> properly for some reason.)</li><li>Concurrency by spawning new threads for incoming requests.</li><li>500 error pages when there are errors ❤ ❤</li></ol><p>Even if we could have made this progress just with Tokio, I don’t think we would have felt very confident with our code. Using std::net gave us just the bare minimum letting us build things on top.</p><p>We did a quick micro-benchmark and we got a throughput of almost 10000 requests per second, which is not that surprising :D Anyway, that’s a useless number at this point.</p><p>So yeah, that’s where we are at the moment. Our next step is to enable CGI Scripting. I am looking forward to that very much as it lets us do some really cool stuff.</p><p>Currently, all our code lives in the main.rs file and hopefully as we make more progress we can break down and modularise the code better.</p><p>In case, you want to see how our project is turning out, here’s a link to the <a href="https://github.com/PritiKumr/rust-httpd"><strong>Github repo</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a1488f337f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adventures-in-rust/moving-to-tcpstream-bye-tokio-5a1488f337f6">Moving to TCPStream, Bye Tokio!</a> was originally published in <a href="https://medium.com/adventures-in-rust">Adventures in Rust</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Peek-a-boo Rust!]]></title>
            <link>https://medium.com/adventures-in-rust/peek-a-boo-rust-cc46dee79ae4?source=rss-282a72573069------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc46dee79ae4</guid>
            <category><![CDATA[adventure]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[hobby]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Preethi Kumar]]></dc:creator>
            <pubDate>Tue, 21 Mar 2017 15:21:09 GMT</pubDate>
            <atom:updated>2019-08-29T19:14:55.915Z</atom:updated>
            <content:encoded><![CDATA[<p>What’s life when there’s no adventure? “Boring Routine”.</p><p>“Adventures in Rust”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ONvyUKkCb1YtWcUeoBhLEw.jpeg" /></figure><p>I’m starting this series with my a colleague to record everything that we encounter in Rust, just to look back and feel good yeara later.</p><p>We came across this <a href="https://github.com/gchaincl/httplab">HN article</a>, an interactive web server that runs in the shell. “Pretty cool”, we thought. Now, what would it take to build a web server on our own was the next thing that hit us.</p><p>We always wanted to have a side project to hack on every day after work and this seemed to be interesting.</p><p>Now that we’ve found something to work on, the next thing was to figure out what language we’re going to be using. For this project, we wanted to use something that we had not used before and something that would introduce us to a new paradigm or programming model. Since our day job was building Rails applications, Ruby (and other similar scripting languages), was out of contention.</p><p>We had some interest in Clojure, but since functional programming and lisp, in general, was foreign to us we did not want to go down that road. Besides we did not want to be dealing with Java libraries and error when doing Clojure.</p><p>And then there is “<strong>Go”</strong>, the new buzz language of the industry. We had already used “Go” for writing a small service in one of our work projects and did not exactly enjoy the experience, although it served the purpose it meant.</p><p>Rust was the next candidate and it sort of felt right to start building our web server with Rust since it is a lightweight, statically typed, compiled language (which would be something very new for us given our background) and we’ve read about its unique features that ensure memory safety and the zero-cost abstractions it provides and always wanted to see what these meant in the real world.</p><blockquote>“Memory Safety”, the term that made us consider Rust a serious option.</blockquote><p>So Rust it was.</p><h4>Baby steps…</h4><p>We started off downloading Rust into our Linux machine which was pretty easy and quick. We got access to the compiler -rustc and cargo , which is the feature-packed build tool for Rust that also handles package management.</p><p>Almost everything we encountered in Rust, we tried to relate it to our everyday work language — Ruby.</p><p>And now it was time to write the customary “Hello, World” app. Compiling and running the app with rustc reminded us about compiling and running C programs in college. *The days we never fully understood what we did!*</p><p>Next, we dug into the Documentation of the language and ran into “<a href="https://doc.rust-lang.org/book/README.html">The Rust book</a>” — which is supposed to be the go-to resource for getting started with Rust.</p><p>The book taught us how to use cargo to set up a new Rust project. Doing this we encountered a totally new markup language called toml(<a href="https://github.com/toml-lang/toml">Tom’s Obvious, Minimal Language</a>) in which the cargo.toml is written, and is used to configure the Rust project and specify its dependencies. <strong>cargo</strong> then uses this to pull all the required dependencies for us and maintains a cargo.lock file which is very similar to what bundler does with the Gemfile.lock in the Ruby world. That’s where the similarity ended for us between Rust and Ruby as we moved on through the Rust book.</p><p>The book explained the basis of the language by building an implementation of the “Guessing Game” in Rust. That’s how we started with Rust.</p><p>We’ll keep adding more stories to this series every week, as we increase the developments to our web server.</p><p>In case, you want to see how our project is turning out, here’s a secret link to our <a href="https://github.com/PritiKumr/rust-httpd"><strong>Github repo</strong></a>. (Yay! As of 21.03.2017, we’ve got a static File server ready) **BIG SMILES**</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc46dee79ae4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adventures-in-rust/peek-a-boo-rust-cc46dee79ae4">Peek-a-boo Rust!</a> was originally published in <a href="https://medium.com/adventures-in-rust">Adventures in Rust</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>