<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>orhan.cn - API</title>
    <link rel="self" type="application/atom+xml" href="https://orhan.cn/tags/api/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://orhan.cn"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-07-30T00:00:00+00:00</updated>
    <id>https://orhan.cn/tags/api/atom.xml</id>
    <entry xml:lang="en">
        <title>Rust 部分更新的三态语义：Option&lt;Option&lt;T&gt;&gt;、Serde 与 SeaORM</title>
        <published>2026-07-30T00:00:00+00:00</published>
        <updated>2026-07-30T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              menzil
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://orhan.cn/posts/rust-partial-update-tristate-seaorm/"/>
        <id>https://orhan.cn/posts/rust-partial-update-tristate-seaorm/</id>
        
        <summary type="html">&lt;p&gt;&lt;code&gt;PATCH &#x2F;users&#x2F;{id}&lt;&#x2F;code&gt; 这类部分更新接口里，一个字段通常不只有“有值”和“没值”两种状态。以 &lt;code&gt;name&lt;&#x2F;code&gt; 为例，客户端可能发送：&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;json&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-json &quot;&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span&gt;{}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;json&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-json &quot;&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span&gt;{&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;null&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;json&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-json &quot;&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span&gt;{&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;: &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;它们的业务含义分别是：不修改 &lt;code&gt;name&lt;&#x2F;code&gt;、将 &lt;code&gt;name&lt;&#x2F;code&gt; 清空为数据库 &lt;code&gt;NULL&lt;&#x2F;code&gt;、将 &lt;code&gt;name&lt;&#x2F;code&gt; 更新为 &lt;code&gt;Alice&lt;&#x2F;code&gt;。&lt;&#x2F;p&gt;
&lt;p&gt;问题的核心不是 Rust 有没有 &lt;code&gt;nil&lt;&#x2F;code&gt;，而是 API 输入确实有三种独立语义。把它们明确建模，才能避免把“字段没传”误当成“清空字段”。&lt;&#x2F;p&gt;</summary>
        
    </entry>
</feed>
