<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ownership on Nalar</title>
    <link>https://nalar.dev/tags/ownership/</link>
    <description>Recent content in Ownership on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 01 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/ownership/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Borrowed or Owned Data in Rust API Design</title>
      <link>https://nalar.dev/borrowed-or-owned-data-in-rust-api-design/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/borrowed-or-owned-data-in-rust-api-design/</guid>
      <description>&lt;p&gt;Rust APIs frequently face a design choice that is more important than syntax: should a function borrow data from the caller or take ownership of it?&lt;/p&gt;&#xA;&lt;p&gt;Borrowing can avoid allocation and make reuse cheap. Ownership can simplify storage and decouple lifetimes. Good APIs use each where it matches the actual data flow.&lt;/p&gt;&#xA;&lt;h2 id=&#34;borrow-when-work-is-temporary&#34;&gt;Borrow when work is temporary&lt;/h2&gt;&#xA;&lt;p&gt;If a function only reads a string during the call, accepting &lt;code&gt;&amp;amp;str&lt;/code&gt; is usually natural:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Choosing &amp;str, String, and Cow for Rust Text APIs</title>
      <link>https://nalar.dev/choosing-str-string-and-cow-for-text-apis/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/choosing-str-string-and-cow-for-text-apis/</guid>
      <description>&lt;p&gt;Rust has several common ways to represent UTF-8 text, and choosing between &lt;code&gt;&amp;amp;str&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt;, and &lt;code&gt;Cow&amp;lt;&#39;a, str&amp;gt;&lt;/code&gt; is fundamentally an ownership decision.&lt;/p&gt;&#xA;&lt;p&gt;The best API is usually the one that asks callers for the least ownership it needs and returns ownership only when the result requires it.&lt;/p&gt;&#xA;&lt;h2 id=&#34;use-str-when-you-only-need-to-read-text&#34;&gt;Use &lt;code&gt;&amp;amp;str&lt;/code&gt; when you only need to read text&lt;/h2&gt;&#xA;&lt;p&gt;A string slice borrows UTF-8 text owned elsewhere:&lt;/p&gt;&#xA;&lt;div &#xA;    x-data=&#34;{&#xA;        code: $el.querySelector(&#39;code&#39;).innerText&#xA;    }&#34;&#xA;    class=&#34;relative my-4 rounded-lg group&#34;&#xA;&gt;&#xA;    &lt;button&#xA;        @click=&#34;navigator.clipboard.writeText(code); $el.innerText = &#39;Copied!&#39;; setTimeout(() =&gt; $el.innerText = &#39;Copy&#39;, 2000)&#34;&#xA;        class=&#34;absolute top-2 right-2 bg-neutral-700 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity&#34;&#xA;    &gt;&#xA;        Copy&#xA;    &lt;/button&gt;&#xA;    &#xA;    &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-rust&#34; data-lang=&#34;rust&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;is_blank&lt;/span&gt;(value: &lt;span style=&#34;color:#66d9ef&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;str&lt;/span&gt;) -&amp;gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;bool&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    value.trim().is_empty()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;This accepts borrowed views into a &lt;code&gt;String&lt;/code&gt;, string literals, and other string slices without taking ownership or allocating.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
