<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rust Standard Library Mastery on Atharva Pandey</title><link>https://atharva.page/series/rust-standard-library-mastery/</link><description>Recent content in Rust Standard Library Mastery on Atharva Pandey</description><generator>Hugo</generator><language>en-us</language><copyright>Copyright ©</copyright><lastBuildDate>Tue, 08 Oct 2024 15:30:00 +0000</lastBuildDate><atom:link href="https://atharva.page/series/rust-standard-library-mastery/index.xml" rel="self" type="application/rss+xml"/><item><title>Lesson 10: Conversion Traits — From, Into, TryFrom, AsRef</title><link>https://atharva.page/post/rust/rust-stdlib-convert/</link><pubDate>Tue, 08 Oct 2024 15:30:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-convert/</guid><description>&lt;p&gt;I used to litter my Rust code with &lt;code&gt;.to_string()&lt;/code&gt;, &lt;code&gt;as&lt;/code&gt;, and manual conversion functions everywhere. Then I learned the conversion traits properly and my APIs went from clunky to clean. These traits are the glue that makes Rust code feel ergonomic — and understanding when to implement each one is the difference between a library that&amp;rsquo;s pleasant to use and one that makes people curse your name.&lt;/p&gt;
&lt;h2 id="from-and-into--infallible-conversion"&gt;From and Into — Infallible Conversion&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;From&amp;lt;T&amp;gt;&lt;/code&gt; defines how to create a type from another type. It can&amp;rsquo;t fail. If there&amp;rsquo;s any possibility of failure, you want &lt;code&gt;TryFrom&lt;/code&gt; instead.&lt;/p&gt;</description></item><item><title>Lesson 9: std::sync — Mutex, RwLock, Once, Barrier</title><link>https://atharva.page/post/rust/rust-stdlib-sync/</link><pubDate>Fri, 04 Oct 2024 13:25:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-sync/</guid><description>&lt;p&gt;I shipped a data race to production exactly once. Go program, shared map, no lock. Took three weeks to reproduce — only happened under heavy load when two goroutines hit the same key simultaneously. The crash dump was useless. In Rust, that code wouldn&amp;rsquo;t have compiled. That&amp;rsquo;s not marketing — it&amp;rsquo;s literally how the type system works.&lt;/p&gt;
&lt;h2 id="arc--shared-ownership-across-threads"&gt;Arc — Shared Ownership Across Threads&lt;/h2&gt;
&lt;p&gt;Before we talk about locks, we need &lt;code&gt;Arc&lt;/code&gt;. You can&amp;rsquo;t share data between threads with just &lt;code&gt;Rc&lt;/code&gt; — it&amp;rsquo;s not thread-safe. &lt;code&gt;Arc&lt;/code&gt; (Atomic Reference Counted) is the thread-safe version.&lt;/p&gt;</description></item><item><title>Lesson 8: std::time — Duration, Instant, SystemTime</title><link>https://atharva.page/post/rust/rust-stdlib-time/</link><pubDate>Tue, 01 Oct 2024 07:50:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-time/</guid><description>&lt;p&gt;A few months ago I tracked down a bug where a cache TTL check was wrong because someone compared &lt;code&gt;SystemTime&lt;/code&gt; values that had been serialized and deserialized across a system clock adjustment. The cached timestamps jumped backward, and suddenly entries that should&amp;rsquo;ve expired were &amp;ldquo;fresh&amp;rdquo; again. That&amp;rsquo;s the kind of lesson that teaches you the difference between monotonic clocks and wall clocks.&lt;/p&gt;
&lt;h2 id="two-clocks-two-types"&gt;Two Clocks, Two Types&lt;/h2&gt;
&lt;p&gt;Rust gives you two time types because computers have two fundamentally different clocks:&lt;/p&gt;</description></item><item><title>Lesson 7: std::process — Running external commands</title><link>https://atharva.page/post/rust/rust-stdlib-process/</link><pubDate>Sun, 29 Sep 2024 19:15:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-process/</guid><description>&lt;p&gt;I once wrote a deployment script in Bash that grew to 800 lines with nested conditionals, string interpolation bugs, and error handling that amounted to &amp;ldquo;hope for the best.&amp;rdquo; Rewrote it in Rust using &lt;code&gt;std::process::Command&lt;/code&gt; — same functionality, but with actual error handling and type safety. The number of failed deployments dropped to zero.&lt;/p&gt;
&lt;h2 id="command--the-builder"&gt;Command — The Builder&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;std::process::Command&lt;/code&gt; is a builder for spawning child processes. You construct the command, configure it, then either run it to completion or spawn it and interact with its I/O.&lt;/p&gt;</description></item><item><title>Lesson 6: std::net — TCP, UDP, sockets</title><link>https://atharva.page/post/rust/rust-stdlib-net/</link><pubDate>Fri, 27 Sep 2024 09:40:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-net/</guid><description>&lt;p&gt;The first network program I ever wrote — a chat server in college — had a bug where it would block forever waiting for one client&amp;rsquo;s message while all the other clients hung. Classic single-threaded socket mistake. Rust&amp;rsquo;s &lt;code&gt;std::net&lt;/code&gt; module gives you the same low-level socket primitives, but the ownership system actually helps you avoid some of those pitfalls.&lt;/p&gt;
&lt;h2 id="tcp--the-reliable-one"&gt;TCP — The Reliable One&lt;/h2&gt;
&lt;p&gt;TCP gives you ordered, reliable byte streams. You connect, you send bytes, they arrive in order (or the connection dies trying). That&amp;rsquo;s the deal.&lt;/p&gt;</description></item><item><title>Lesson 5: std::fmt — Formatting internals</title><link>https://atharva.page/post/rust/rust-stdlib-fmt/</link><pubDate>Tue, 24 Sep 2024 11:05:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-fmt/</guid><description>&lt;p&gt;I once shipped a monitoring dashboard where all the latency values showed up as &amp;ldquo;Duration { secs: 0, nanos: 234000000 }&amp;rdquo; because I&amp;rsquo;d used &lt;code&gt;{:?}&lt;/code&gt; instead of implementing &lt;code&gt;Display&lt;/code&gt;. That&amp;rsquo;s the kind of thing that makes you sit down and actually learn how formatting works.&lt;/p&gt;
&lt;h2 id="display-vs-debug"&gt;Display vs. Debug&lt;/h2&gt;
&lt;p&gt;These two traits are the foundation of everything in &lt;code&gt;std::fmt&lt;/code&gt;. Every time you use &lt;code&gt;println!&lt;/code&gt;, &lt;code&gt;format!&lt;/code&gt;, or &lt;code&gt;write!&lt;/code&gt;, you&amp;rsquo;re invoking one of them.&lt;/p&gt;</description></item><item><title>Lesson 4: std::fs and std::path — Filesystem operations done right</title><link>https://atharva.page/post/rust/rust-stdlib-fs/</link><pubDate>Sat, 21 Sep 2024 16:10:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-fs/</guid><description>&lt;p&gt;A colleague once deployed a script that used string concatenation for file paths: &lt;code&gt;dir + &amp;quot;/&amp;quot; + filename&lt;/code&gt;. Worked perfectly on Linux, blew up on Windows, and silently corrupted paths when &lt;code&gt;dir&lt;/code&gt; ended with a slash. Rust&amp;rsquo;s &lt;code&gt;Path&lt;/code&gt; type exists specifically to prevent this class of bug.&lt;/p&gt;
&lt;h2 id="path-vs-pathbuf--the-strstring-split"&gt;Path vs. PathBuf — The &amp;amp;str/String Split&lt;/h2&gt;
&lt;p&gt;Just like Rust has &lt;code&gt;&amp;amp;str&lt;/code&gt; (borrowed) and &lt;code&gt;String&lt;/code&gt; (owned), it has &lt;code&gt;&amp;amp;Path&lt;/code&gt; (borrowed) and &lt;code&gt;PathBuf&lt;/code&gt; (owned). The duality is identical:&lt;/p&gt;</description></item><item><title>Lesson 3: std::io — Read, Write, BufRead, Seek</title><link>https://atharva.page/post/rust/rust-stdlib-io/</link><pubDate>Thu, 19 Sep 2024 08:30:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-io/</guid><description>&lt;p&gt;Early in my Rust journey, I wrote a log parser that read a 2GB file byte by byte using &lt;code&gt;read()&lt;/code&gt; without buffering. It took forty minutes. Adding a &lt;code&gt;BufReader&lt;/code&gt; wrapper — one line of code — brought it down to three seconds. That&amp;rsquo;s when I learned that understanding &lt;code&gt;std::io&lt;/code&gt; isn&amp;rsquo;t optional.&lt;/p&gt;
&lt;h2 id="the-four-core-traits"&gt;The Four Core Traits&lt;/h2&gt;
&lt;p&gt;Rust&amp;rsquo;s I/O system is built on four traits. Everything — files, network sockets, stdin, pipes, in-memory buffers — implements some combination of these:&lt;/p&gt;</description></item><item><title>Lesson 2: Iterator Trait and Adapters — The full picture</title><link>https://atharva.page/post/rust/rust-stdlib-iterators/</link><pubDate>Tue, 17 Sep 2024 14:45:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-iterators/</guid><description>&lt;p&gt;The moment Rust iterators clicked for me was when I realized they&amp;rsquo;re not loops with extra steps — they&amp;rsquo;re a completely different way of expressing data transformations. I&amp;rsquo;d been writing imperative loops for fifteen years, and the first time I refactored a gnarly nested-loop function into an iterator chain, the result was half the lines and twice as readable.&lt;/p&gt;
&lt;h2 id="the-iterator-trait"&gt;The Iterator Trait&lt;/h2&gt;
&lt;p&gt;Everything starts here. The &lt;code&gt;Iterator&lt;/code&gt; trait is shockingly simple:&lt;/p&gt;</description></item><item><title>Lesson 1: Collections Deep Dive — Vec, VecDeque, BTreeMap and when to use which</title><link>https://atharva.page/post/rust/rust-stdlib-collections/</link><pubDate>Sun, 15 Sep 2024 10:22:00 +0000</pubDate><guid>https://atharva.page/post/rust/rust-stdlib-collections/</guid><description>&lt;p&gt;I spent two days debugging a performance cliff in a data pipeline — turns out I&amp;rsquo;d been using a &lt;code&gt;HashMap&lt;/code&gt; where a &lt;code&gt;BTreeMap&lt;/code&gt; would&amp;rsquo;ve cut iteration time in half because I needed sorted output downstream. The collection you pick matters more than most people think.&lt;/p&gt;
&lt;h2 id="the-big-picture"&gt;The Big Picture&lt;/h2&gt;
&lt;p&gt;Rust&amp;rsquo;s standard library ships a small but deliberate set of collections. Unlike languages that give you seventeen flavors of list, Rust gives you a few well-designed options and expects you to understand the trade-offs. That&amp;rsquo;s actually a feature — fewer choices means you can develop genuine intuition about when to use what.&lt;/p&gt;</description></item></channel></rss>