<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Rust on terurin&#39;s lab</title>
		<link>https://terurin.work/tags/rust/</link>
		<description>Recent content in Rust on terurin&#39;s lab</description>
		<generator>Hugo</generator>
		<language>jp</language>
		
		
		
		
			<lastBuildDate>Tue, 17 Feb 2026 22:32:38 +0900</lastBuildDate>
		
			<atom:link href="https://terurin.work/tags/rust/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>vscodeでパーサージェネレータpest独自形式のコードをフォーマットする</title>
				<link>https://terurin.work/posts/rust-pest/vscode-pestfmt/</link>
				<pubDate>Tue, 17 Feb 2026 22:32:38 +0900</pubDate>
				<guid>https://terurin.work/posts/rust-pest/vscode-pestfmt/</guid>
				<description>&lt;h2 id=&#34;概要&#34;&gt;概要&lt;/h2&gt;&#xA;&lt;p&gt;rustのパーサージェネレータに&lt;code&gt;pest&lt;/code&gt;というライブラリがある。&#xA;パーサーを生成する際に独自の&lt;code&gt;pest&lt;/code&gt;形式のファイルを利用するが、&#xA;2026/02/17現在、既存のvscodeのプラグインでフォーマットできない。&lt;/p&gt;&#xA;&lt;p&gt;そこで汎用的なvscodeのフォーマットのラッパープラグインである&#xA;&lt;code&gt;vscode-custom-local-formatters&lt;/code&gt;と&#xA;cargoでインストールできる&lt;code&gt;pest-fmt&lt;/code&gt;を用いて&lt;code&gt;*.pest&lt;/code&gt;形式のファイルを&#xA;フォーマットする方法を示す。&lt;/p&gt;&#xA;&lt;h2 id=&#34;前提条件&#34;&gt;前提条件&lt;/h2&gt;&#xA;&lt;p&gt;前提条件はつぎのとおりである。&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;rustのパッケージマネージャである&lt;code&gt;cargo&lt;/code&gt;がインストールされていること&#xA;&lt;ul&gt;&#xA;&lt;li&gt;インストール方法は&lt;a href=&#34;https://rust-lang.org/ja/tools/install/&#34;&gt;公式サイト&lt;/a&gt;を参照してください。&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;${HOME}/.cargo/bin&lt;/code&gt;がPATHに登録されていること&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;シェル(例: &lt;code&gt;bash&lt;/code&gt;)が動作すること&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;手順&#34;&gt;手順&lt;/h2&gt;&#xA;&lt;p&gt;最初にpestのフォーマッターである&lt;code&gt;pestfmt&lt;/code&gt;をインストールする。&lt;/p&gt;&#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;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;cargo install pest_fmt&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;次にvscodeで次のプラグインをインストールする。&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;vscode-custom-local-formatters&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;そして次のように&lt;code&gt;settings.json&lt;/code&gt;に書く。&lt;/p&gt;&#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;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-json&#34; data-lang=&#34;json&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;customLocalFormatters.formatters&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;:&lt;/span&gt; [&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;languages&amp;#34;&lt;/span&gt;: [&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;pest&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ],&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;command&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;bash -c \&amp;#34;pestfmt ${file} &amp;gt;/dev/null &amp;amp;&amp;amp; cat ${file}\&amp;#34;&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;style type=&#34;text/css&#34;&gt;&#xA;     &#xA;    .notice {&#xA;        --title-color: #fff;&#xA;        --title-background-color: #6be;&#xA;        --content-color: #444;&#xA;        --content-background-color: #e7f2fa;&#xA;    }&#xA;&#xA;    .notice.info {&#xA;        --title-background-color: #fb7;&#xA;        --content-background-color: #fec;&#xA;    }&#xA;&#xA;    .notice.tip {&#xA;        --title-background-color: #5a5;&#xA;        --content-background-color: #efe;&#xA;    }&#xA;&#xA;    .notice.warning {&#xA;        --title-background-color: #c33;&#xA;        --content-background-color: #fee;&#xA;    }&#xA;&#xA;     &#xA;    @media (prefers-color-scheme:dark) {&#xA;        .notice {&#xA;            --title-color: #fff;&#xA;            --title-background-color: #069;&#xA;            --content-color: #ddd;&#xA;            --content-background-color: #023;&#xA;        }&#xA;&#xA;        .notice.info {&#xA;            --title-background-color: #a50;&#xA;            --content-background-color: #420;&#xA;        }&#xA;&#xA;        .notice.tip {&#xA;            --title-background-color: #363;&#xA;            --content-background-color: #121;&#xA;        }&#xA;&#xA;        .notice.warning {&#xA;            --title-background-color: #800;&#xA;            --content-background-color: #400;&#xA;        }&#xA;    }&#xA;&#xA;    body.dark .notice {&#xA;        --title-color: #fff;&#xA;        --title-background-color: #069;&#xA;        --content-color: #ddd;&#xA;        --content-background-color: #023;&#xA;    }&#xA;&#xA;    body.dark .notice.info {&#xA;        --title-background-color: #a50;&#xA;        --content-background-color: #420;&#xA;    }&#xA;&#xA;    body.dark .notice.tip {&#xA;        --title-background-color: #363;&#xA;        --content-background-color: #121;&#xA;    }&#xA;&#xA;    body.dark .notice.warning {&#xA;        --title-background-color: #800;&#xA;        --content-background-color: #400;&#xA;    }&#xA;&#xA;     &#xA;    .notice {&#xA;        padding: 18px;&#xA;        line-height: 24px;&#xA;        margin-bottom: 24px;&#xA;        border-radius: 4px;&#xA;        color: var(--content-color);&#xA;        background: var(--content-background-color);&#xA;    }&#xA;&#xA;    .notice p:last-child {&#xA;        margin-bottom: 0&#xA;    }&#xA;&#xA;     &#xA;    .notice-title {&#xA;        margin: -18px -18px 12px;&#xA;        padding: 4px 18px;&#xA;        border-radius: 4px 4px 0 0;&#xA;        font-weight: 700;&#xA;        color: var(--title-color);&#xA;        background: var(--title-background-color);&#xA;    }&#xA;&#xA;     &#xA;    .icon-notice {&#xA;        display: inline-flex;&#xA;        align-self: center;&#xA;        margin-right: 8px;&#xA;    }&#xA;&#xA;    .icon-notice img,&#xA;    .icon-notice svg {&#xA;        height: 1em;&#xA;        width: 1em;&#xA;        fill: currentColor;&#xA;    }&#xA;&#xA;    .icon-notice img,&#xA;    .icon-notice.baseline svg {&#xA;        top: .125em;&#xA;        position: relative;&#xA;    }&#xA;&lt;/style&gt;&lt;div class=&#34;notice tip&#34; &gt;&#xA;    &lt;p class=&#34;notice-title&#34;&gt;&#xA;        &lt;span class=&#34;icon-notice baseline&#34;&gt;&#xA;            &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;300.5 134 300 300&#34;&gt;&#xA;  &lt;path d=&#34;M551.281 252.36c0-3.32-1.172-6.641-3.515-8.985l-17.774-17.578c-2.344-2.344-5.469-3.711-8.789-3.711-3.32 0-6.445 1.367-8.789 3.71l-79.687 79.493-44.141-44.14c-2.344-2.344-5.469-3.712-8.79-3.712-3.32 0-6.444 1.368-8.788 3.711l-17.774 17.579c-2.343 2.343-3.515 5.664-3.515 8.984 0 3.32 1.172 6.445 3.515 8.789l70.704 70.703c2.343 2.344 5.664 3.711 8.789 3.711 3.32 0 6.64-1.367 8.984-3.71l106.055-106.056c2.343-2.343 3.515-5.468 3.515-8.789ZM600.5 284c0 82.813-67.188 150-150 150-82.813 0-150-67.188-150-150 0-82.813 67.188-150 150-150 82.813 0 150 67.188 150 150Z&#34;/&gt;&#xA;&lt;/svg&gt;&#xA;&#xA;        &lt;/span&gt;Tip&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
