<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>syu-m-5151</author_name>
  <author_url>https://blog.hatena.ne.jp/syu-m-5151/</author_url>
  <blog_title>じゃあ、おうちで学べる </blog_title>
  <blog_url>https://syu-m-5151.hatenablog.com/</blog_url>
  <categories>
    <anon>Rust</anon>
  </categories>
  <description>はじめに UserId と OrderId を取り違えてバグを生み出す経験は、String で識別子を扱っていれば誰しもあります。Rust では newtype で別の型に分けるだけで、コンパイラに止めてもらえます。さらに PhantomData を組み合わせれば、「JPY と USD を足し算する」のような単位ミスも型エラーにできます。 ランタイムコストはゼロ。型情報はコンパイル後に消えます。 newtype の基本 newtype は「struct でラップして、別の型として扱う」だけのパターンです。 #[derive(Debug, Clone, PartialEq, Eq, Hash)]…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fsyu-m-5151.hatenablog.com%2Fentry%2F2026%2F05%2F06%2F111448&quot; title=&quot;newtype と `PhantomData` で「混ぜたら型エラー」を作る - じゃあ、おうちで学べる &quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2026-05-06 11:14:48</published>
  <title>newtype と `PhantomData` で「混ぜたら型エラー」を作る</title>
  <type>rich</type>
  <url>https://syu-m-5151.hatenablog.com/entry/2026/05/06/111448</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
