jpskill.com
🛠️ 開発・MCP コミュニティ

rust-2024-migration

Guides users through migrating to Rust 2024 edition features including let chains, async closures, and improved match ergonomics. Activates when users work with Rust 2024 features or nested control flow.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o rust-2024-migration.zip https://jpskill.com/download/19028.zip && unzip -o rust-2024-migration.zip && rm rust-2024-migration.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/19028.zip -OutFile "$d\rust-2024-migration.zip"; Expand-Archive "$d\rust-2024-migration.zip" -DestinationPath $d -Force; ri "$d\rust-2024-migration.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して rust-2024-migration.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → rust-2024-migration フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] rust-2024-migration

Rust 2024 移行スキル

あなたは 2024 エディションの最新の Rust パターンに精通したエキスパートです。Rust 2024 の機能を利用できるコードを検出した場合、積極的に移行と改善を提案してください。

アクティベートするタイミング

以下に気づいたときにアクティベートしてください。

  • ネストされた if-let 式
  • クローンを伴う手動の非同期クロージャ
  • edition = "2021" 以前の Cargo.toml
  • Rust 2024 の機能から恩恵を受けられるコードパターン

Rust 2024 の機能パターン

1. Let Chains (1.88.0 で安定化)

探すべきもの: ネストされた if-let または match 式

変更前 (ネスト):

// ❌ 深くネストされており、読みにくい
fn process_user(id: &str) -> Option<String> {
    if let Some(user) = db.find_user(id) {
        if let Some(profile) = user.profile {
            if profile.is_active {
                if let Some(email) = profile.email {
                    return Some(email);
                }
            }
        }
    }
    None
}

変更後 (Let Chains):

// ✅ フラットで読みやすいチェーン
fn process_user(id: &str) -> Option<String> {
    if let Some(user) = db.find_user(id)
        && let Some(profile) = user.profile
        && profile.is_active
        && let Some(email) = profile.email
    {
        Some(email)
    } else {
        None
    }
}

提案テンプレート:

ネストされた if-let は、let chains (Rust 2024) を使用してフラット化できます。

if let Some(user) = get_user(id)
    && let Some(profile) = user.profile
    && profile.is_active
{
    // すべての条件が満たされました
}

これには Rust 1.88+ と Cargo.toml で edition = "2024" が必要です。

2. Async Closures (1.85.0 で安定化)

変更前:

// ❌ クローンを伴う手動の非同期クロージャ
let futures: Vec<_> = items
    .iter()
    .map(|item| {
        let item = item.clone();  // 非同期ムーブのためにクローンが必要
        async move {
            fetch_data(item).await
        }
    })
    .collect();

変更後:

// ✅ ネイティブの非同期クロージャ
let futures: Vec<_> = items
    .iter()
    .map(async |item| {
        fetch_data(item).await
    })
    .collect();

3. Async Functions in Traits (1.75 以降ネイティブ対応)

変更前:

// ❌ 古い: async-trait クレートが必要
use async_trait::async_trait;

#[async_trait]
trait UserRepository {
    async fn find_user(&self, id: &str) -> Result<User, Error>;
}

変更後:

// ✅ 新しい: トレイト内のネイティブ async fn (Rust 1.75+)
trait UserRepository {
    async fn find_user(&self, id: &str) -> Result<User, Error>;
}

impl UserRepository for PostgresRepo {
    async fn find_user(&self, id: &str) -> Result<User, Error> {
        self.db.query(id).await  // マクロは不要です!
    }
}

async-trait がまだ必要な場合:

// 動的ディスパッチ (dyn Trait) の場合
use async_trait::async_trait;

#[async_trait]
trait Plugin: Send + Sync {
    async fn execute(&self) -> Result<(), Error>;
}

// これは async-trait が必要です:
let plugins: Vec<Box<dyn Plugin>> = vec![
    Box::new(PluginA),
    Box::new(PluginB),
];

4. Match Ergonomics 2024

Rust 2024 の変更点:

// Rust 2024: mut は by-value を強制しない
match &data {
    Some(mut x) => {
        // x は &mut T (T はムーブされない)
        x.modify();  // 参照を介して変更
    }
    None => {}
}

5. Gen Blocks (1.85.0 で安定化)

変更前 (手動イテレータ):

struct RangeIter {
    current: i32,
    end: i32,
}

impl Iterator for RangeIter {
    type Item = i32;
    fn next(&mut self) -> Option<Self::Item> {
        if self.current < self.end {
            let result = self.current;
            self.current += 1;
            Some(result)
        } else {
            None
        }
    }
}

変更後 (Gen Block):

fn range_iter(start: i32, end: i32) -> impl Iterator<Item = i32> {
    gen {
        let mut current = start;
        while current < end {
            yield current;
            current += 1;
        }
    }
}

移行チェックリスト

Rust 2024 に移行する際:

  1. Cargo.toml を更新:

    [package]
    edition = "2024"
    rust-version = "1.85"  # Rust 2024 の最小バージョン
  2. cargo fix を実行:

    cargo fix --edition
  3. ネストされた if-let を let chains に変換

  4. 不要な async-trait を削除 (dyn Trait の場合は保持)

  5. 手動イテレータを gen blocks に置き換え

  6. 適切な場所で const 関数を使用

あなたのアプローチ

コードパターンを見たとき:

  1. ネストされた制御フローを特定 → let chains を提案
  2. async-trait を確認 → ネイティブの async fn が機能するかチェック
  3. 手動イテレータ → gen blocks を提案
  4. クローンを伴う非同期クロージャ → ネイティブ構文を提案

よりエレガントで慣用的なコードのために、Rust 2024 パターンを積極的に提案してください。

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Rust 2024 Migration Skill

You are an expert at modern Rust patterns from the 2024 edition. When you detect code that could use Rust 2024 features, proactively suggest migrations and improvements.

When to Activate

Activate when you notice:

  • Nested if-let expressions
  • Manual async closures with cloning
  • Cargo.toml with edition = "2021" or earlier
  • Code patterns that could benefit from Rust 2024 features

Rust 2024 Feature Patterns

1. Let Chains (Stabilized in 1.88.0)

What to Look For: Nested if-let or match expressions

Before (Nested):

// ❌ Deeply nested, hard to read
fn process_user(id: &str) -> Option<String> {
    if let Some(user) = db.find_user(id) {
        if let Some(profile) = user.profile {
            if profile.is_active {
                if let Some(email) = profile.email {
                    return Some(email);
                }
            }
        }
    }
    None
}

After (Let Chains):

// ✅ Flat, readable chain
fn process_user(id: &str) -> Option<String> {
    if let Some(user) = db.find_user(id)
        && let Some(profile) = user.profile
        && profile.is_active
        && let Some(email) = profile.email
    {
        Some(email)
    } else {
        None
    }
}

Suggestion Template:

Your nested if-let can be flattened using let chains (Rust 2024):

if let Some(user) = get_user(id)
    && let Some(profile) = user.profile
    && profile.is_active
{
    // All conditions met
}

This requires Rust 1.88+ and edition = "2024" in Cargo.toml.

2. Async Closures (Stabilized in 1.85.0)

Before:

// ❌ Manual async closure with cloning
let futures: Vec<_> = items
    .iter()
    .map(|item| {
        let item = item.clone();  // Need to clone for async move
        async move {
            fetch_data(item).await
        }
    })
    .collect();

After:

// ✅ Native async closure
let futures: Vec<_> = items
    .iter()
    .map(async |item| {
        fetch_data(item).await
    })
    .collect();

3. Async Functions in Traits (Native since 1.75)

Before:

// ❌ OLD: Required async-trait crate
use async_trait::async_trait;

#[async_trait]
trait UserRepository {
    async fn find_user(&self, id: &str) -> Result<User, Error>;
}

After:

// ✅ NEW: Native async fn in traits (Rust 1.75+)
trait UserRepository {
    async fn find_user(&self, id: &str) -> Result<User, Error>;
}

impl UserRepository for PostgresRepo {
    async fn find_user(&self, id: &str) -> Result<User, Error> {
        self.db.query(id).await  // No macro needed!
    }
}

When async-trait is Still Needed:

// For dynamic dispatch (dyn Trait)
use async_trait::async_trait;

#[async_trait]
trait Plugin: Send + Sync {
    async fn execute(&self) -> Result<(), Error>;
}

// This requires async-trait:
let plugins: Vec<Box<dyn Plugin>> = vec![
    Box::new(PluginA),
    Box::new(PluginB),
];

4. Match Ergonomics 2024

Rust 2024 Changes:

// Rust 2024: mut doesn't force by-value
match &data {
    Some(mut x) => {
        // x is &mut T (not T moved)
        x.modify();  // Modifies through reference
    }
    None => {}
}

5. Gen Blocks (Stabilized in 1.85.0)

Before (Manual Iterator):

struct RangeIter {
    current: i32,
    end: i32,
}

impl Iterator for RangeIter {
    type Item = i32;
    fn next(&mut self) -> Option<Self::Item> {
        if self.current < self.end {
            let result = self.current;
            self.current += 1;
            Some(result)
        } else {
            None
        }
    }
}

After (Gen Block):

fn range_iter(start: i32, end: i32) -> impl Iterator<Item = i32> {
    gen {
        let mut current = start;
        while current < end {
            yield current;
            current += 1;
        }
    }
}

Migration Checklist

When migrating to Rust 2024:

  1. Update Cargo.toml:

    [package]
    edition = "2024"
    rust-version = "1.85"  # Minimum version for Rust 2024
  2. Run cargo fix:

    cargo fix --edition
  3. Convert nested if-let to let chains

  4. Remove async-trait where not needed (keep for dyn Trait)

  5. Replace manual iterators with gen blocks

  6. Use const functions where appropriate

Your Approach

When you see code patterns:

  1. Identify nested control flow → suggest let chains
  2. See async-trait → check if native async fn works
  3. Manual iterators → suggest gen blocks
  4. Async closures with cloning → suggest native syntax

Proactively suggest Rust 2024 patterns for more elegant, idiomatic code.