[{"data":1,"prerenderedAt":711},["ShallowReactive",2],{"/ja-jp/blog/learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions":3,"navigation-ja-jp":39,"banner-ja-jp":454,"footer-ja-jp":467,"footer-source-/ja-jp/blog/learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions/":677,"Michael Friedrich":683,"next-steps-ja-jp":696},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"seo":8,"content":16,"config":29,"_id":32,"_type":33,"title":34,"_source":35,"_file":36,"_stem":37,"_extension":38},"/ja-jp/blog/learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions","blog",false,"",{"title":9,"description":10,"ogTitle":9,"ogDescription":10,"noIndex":6,"ogImage":11,"ogUrl":12,"ogSiteName":13,"ogType":14,"canonicalUrls":12,"schema":15},"AIを活用して学ぶ、Rustの高度なプログラミング","このガイド付きチュートリアルでは、AIを搭載したGitLab Duoのコード提案を活用しながら、Rustの高度なプログラミングを学ぶことができます。","https://res.cloudinary.com/about-gitlab-com/image/upload/v1749662439/Blog/Hero%20Images/codewithheart.png","https://about.gitlab.com/blog/learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions","https://about.gitlab.com","article","\n                        {\n        \"@context\": \"https://schema.org\",\n        \"@type\": \"Article\",\n        \"headline\": \"AIを活用して学ぶ、Rustの高度なプログラミング\",\n        \"author\": [{\"@type\":\"Person\",\"name\":\"Michael Friedrich\"}],\n        \"datePublished\": \"2023-10-12\",\n      }",{"title":9,"description":10,"authors":17,"heroImage":11,"date":19,"body":20,"category":21,"tags":22,"updatedDate":28},[18],"Michael Friedrich","2023-10-12","20年以上前に新しいプログラミング言語を学び始めたとき、私たちは6枚のCD-ROMからインストールしたVisual Studio\n6のMSDNライブラリにアクセスしていました。ペンと紙でアルゴリズムを記録し、設計パターンの本を読み漁り、MSDNで正しい型を調べていましたが、こうした作業に時間がかかることが多々ありました。しかし、リモートコラボレーションや人工知能（AI）の時代が到来し、プログラミング言語の学び方は根本的に変わりました。今では[リモート開発環境](https://about.gitlab.com/blog/quick-start-guide-for-gitlab-workspaces/)をすばやく立ち上げて画面を共有し、グループでのプログラミングセッションを行えるようになりました。[GitLab\nDuoのコード提案](https://about.gitlab.com/ja-jp/gitlab-duo/)を使用すれば、AIというインテリジェントなパートナーにいつでも頼ることができます。コード提案機能は、ユーザーのプログラミングのスタイルと経験に基づいて学習します。この機能は、インプットとコンテキストさえあれば、最も効率的な提案を提供してくれるのです。\n\n\nこのチュートリアルでは、[入門編のブログ記事](/blog/learning-rust-with-a-little-help-from-ai-code-suggestions-getting-started/)（英語）からさらに一歩踏み込み、シンプルなフィードリーダーアプリケーションの設計と作成に取り組みます。\n\n\n- 準備\n    - コード提案\n- Rustの学習の継続\n    - 「Hello, Reader!」アプリ\n    - プロジェクトの初期化\n    - RSSフィードURLの定義\n- モジュール\n    - main() 関数によるモジュール関数の呼び出し\n- クレート\n    - feed-rs：XMLフィードの解析\n- ランタイム設定：プログラム引数\n    - ユーザー入力のエラーハンドリング\n- 永続性とデータ保存\n\n- 最適化\n    - 非同期実行\n    - スレッドの生成\n    - 関数スコープ、スレッド、クロージャ\n- フィードのXMLの解析およびオブジェクト型への変換\n    - 汎用的なフィードデータ型のマッピング\n    - Option::unwrap()によるエラーハンドリング\n- ベンチマーク\n    - 逐次実行と並列実行のベンチマークの比較\n    - Rustのキャッシュを使用したCI/CD\n- 次のステップ\n    - 非同期学習の演習\n    - フィードバックの共有\n\n## 準備\n\nソースコードを参照する前に、[VS\nCode](/blog/learning-rust-with-a-little-help-from-ai-code-suggestions-getting-started/#vs-code)と[Rustの開発環境](/blog/learning-rust-with-a-little-help-from-ai-code-suggestions-getting-started/#development-environment-for-rust)をセットアップしてください。\n\n\n### コード提案\n\n実際に提案機能を検証する前に、まずはこの機能の使い方を理解しましょう。GitLab\nDuoのコード提案は、特定のキーボードショートカットを必要とせず、キーを入力するだけで使用できます。たとえば、コード提案を受け入れるには、`Tab`\nキーを押します。また、新しく作成したコードの方が、既存のコードをリファクタリングしたものよりもエラー発生率が低くなる点も覚えておきましょう。AIは非決定的であるため、一度削除したコード提案は再び同じ形で提示されない可能性があります。コード提案は現在ベータ版であり、GitLabは、同機能が生成するコンテンツの全体的な精度向上に取り組んでいます。\n\n\n**ヒント**：コード提案の最新リリースでは、複数行の指示文に対応しています。ニーズに合わせて指示文を調整することで、よりよい提案を得ることができます。\n\n\n```rust\n    // Create a function that iterates over the source array\n    // and fetches the data using HTTP from the RSS feed items.\n    // Store the results in a new hash map.\n    // Print the hash map to the terminal.\n```\n\n\nVS Code拡張機能のオーバーレイは、提案を提示する際に表示されます。提案された行を受け入れるには `Tab` キーを使用し、一単語だけ受け入れるには\n`Cmd + 右カーソル` キーを使用します。さらに、三点リーダーメニューからツールバーを常に表示するオプションを選択することも可能です。\n\n\n![VS CodeにおけるGitLab\nDuoの指示文とコード提案のオーバーレイ](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_code_suggestions_options_overlay_keep_toolbar.png){:\n.shadow}\n\n\n## Rustの学習の継続\n\nでは、引き続きRustについて学んでいきましょう。Rustは[コード提案でサポートされている言語](https://docs.gitlab.com/ee/user/project/repository/code_suggestions/)のひとつです。[Rust\nby\nExample](https://doc.rust-lang.org/rust-by-example/)（英語）では、初心者に最適なチュートリアルが提供されており、公式の[Rust\nBook](https://doc.rust-lang.org/book/)（英語）を確認しながら進めると効果的です。どちらのリソースもこのブログの執筆の際に参考にしています。\n\n\n### 「Hello, Reader!」アプリ\n\nアプリケーションの作成やRustの学習には、さまざまなアプローチがあります。その中には、既存のRustライブラリ、いわゆる `Crates`\nを利用するものがあり、このブログ記事の後半でも使用します。たとえば、画像を処理して、その結果をファイルに書き込むコマンドラインアプリを作成することができます。また、昔ながらの迷路をクリアしたり、数独を解いたりするアプリケーションを作成するのも楽しいでしょうし、ゲーム開発を行うこともできます。たとえば、[Hands-on\nRust](https://hands-on-rust.com/)（英語）というガイドブックでは、ダンジョンクローラー（迷宮探検）ゲームを作りながら、Rustを体系的に学習できるコースを提供しています。筆者の同僚であるFatima\nSarah Khalidは、[AIを活用してC++でDragon\nRealmの制作](/blog/building-a-text-adventure-using-cplusplus-and-code-suggestions/)（英語）を始めたそうです。ぜひそちらもご覧ください。\n\n\nここで、実際の問題を解決するのに役立つ実用的なユースケースをひとつご紹介します。それは、異なるソースから重要な情報をRSSフィードに集約するというものです。RSSフィードには、セキュリティリリース、ブログ記事、およびソーシャルディスカッションフォーラム（Hacker\nNewsなど）の最新情報が含まれます。アップデートに含まれる特定のキーワードやバージョンを絞り込んで検索したいと考えることがよくあります。こうしたニーズを基に、アプリケーションの要件をリスト化できます。具体的には、次のような要件です。\n\n\n1. HTTPウェブサイト、REST API、RSSフィードなどの異なるソースからデータをフェッチ（取得）する（最初の段階ではRSSフィードを使用）。\n\n1. データを解析する。\n\n1. データをユーザーに提示する、またはディスクに書き込む。\n\n1. パフォーマンスを最適化する。\n\n\nこのブログ記事の学習ステップを完了すると、以下のサンプルアプリケーションの出力が得られます。\n\n\n![VS Codeのターミナルでのcargo\nrunの実行と、形成されたフィードエントリの出力](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_cargo_run_formatted_output_final.png)\n\n\nアプリケーションはモジュール化されている必要があり、また、将来的にデータ型やフィルター、アクションをトリガーするフックを追加できる基盤も整えておく必要があります。\n\n\n### プロジェクトの初期化\n\nリマインダー：`cargo init` をプロジェクトのルートディレクトリで実行すると、 `main ()`\nエントリポイントを含んだファイル構造が作成されます。これを踏まえ、次のステップでは、Rustのモジュールの作成と使用方法を学びます。\n\n\n`learn-rust-ai-app-reader` という名前のディレクトリを新規作成し、そのディレクトリに移動したら、`cargo init`\nを実行します。このコマンドは、暗黙的に `git init`\nを実行し、新しいGitリポジトリをローカルで初期化します。残りのステップでは、Gitリモートリポジトリのパスを設定していきます。たとえば、`https://gitlab.com/gitlab-de/use-cases/ai/learn-with-ai/learn-rust-ai-app-reader`\nのように設定します（ご自身のネームスペースに合わせてパスを置き換えてください）。[Gitリポジトリをプッシュ](https://about.gitlab.com/ja-jp/blog/mastering-the-basics-of-git-push-tag/)すると、[GitLabで新しいプロジェクトが自動的に作成](https://docs.gitlab.com/ee/user/project/#create-a-new-project-with-git-push)されます。\n\n\n```shell\n\nmkdir learn-rust-ai-app-reader\n\ncd learn-rust-ai-app-reader\n\n\ncargo init\n\n\ngit remote add origin\nhttps://gitlab.com/gitlab-de/use-cases/ai/learn-with-ai/learn-rust-ai-app-reader.git\n\ngit push --set-upstream origin main\n\n```\n\n\n新しく作成されたディレクトリからVS Codeを開きます。`code` コマンドラインインターフェース（CLI）によって、macOS上で新しいVS\nCodeのウィンドウが起動します。\n\n\n```shell\n\ncode .\n\n```\n\n\n### RSSフィードURLの定義\n\n新しいHashMapを追加して、`src/main.rs` ファイル内の `main()`\n関数にRSSフィードのURLを保存します。複数行の指示コメントを入力することで、GitLab\nDuoのコード提案に対し、[`HashMap`](https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html)\nオブジェクトを作成して、Hacker\nNewsやTechCrunchのデフォルト値で初期化するよう指示できます。注：提案に含まれるURLが正しいことを確認してください。\n\n\n```rust\n\nfn main() {##$_0A$##    // Define RSS feed URLs in the variable\nrss_feeds##$_0A$##    // Use a HashMap##$_0A$##    // Add Hacker News and\nTechCrunch##$_0A$##    // Ensure to use String as type##$_0A$####$_0A$##}\n\n```\n\n\nコードコメントでは以下の点を指示しています。\n\n\n1. 変数名 `rss_feeds`\n\n2. `HashMap` タイプ\n\n3. 3. 初期のseedキー/バリューペア\n\n4. String 型（`to_string ()` 呼び出しで確認可能）\n\n\n考えられるコードの例は次の通りです。\n\n\n```rust\n\nuse std::collections::HashMap;\n\n\nfn main() {##$_0A$##    // Define RSS feed URLs in the variable\nrss_feeds##$_0A$##    // Use a HashMap##$_0A$##    // Add Hacker News and\nTechCrunch##$_0A$##    // Ensure to use String as type##$_0A$##    let\nrss_feeds = HashMap::from([##$_0A$##        (\"Hacker News\".to_string(),\n\"https://news.ycombinator.com/rss\".to_string()),##$_0A$##       \n(\"TechCrunch\".to_string(),\n\"https://techcrunch.com/feed/\".to_string()),##$_0A$##   \n]);##$_0A$####$_0A$##}\n\n```\n\n\n![VS Codeにおける、コード提案を活用したHacker\nNewsとTechCrunchのRSSフィードURLの提案](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_main_array_rss_feed_urls_suggested.png)\n\n\nVS Codeで新しいターミナルを開き（cmd + shift + p で `terminal` を検索）、`cargo build`\nを実行して変更をビルドします。エラーメッセージが表示され、`use std::collections::HashMap;`\nのインポートを追加するよう指示されます。\n\n\n次のステップでは、RSSフィードのURLを使用して操作を行います。[以前のブログ記事](/blog/learning-rust-with-a-little-help-from-ai-code-suggestions-getting-started/)（英語）では、コードを関数に分割する方法を解説しました。今回は、リーダーアプリケーションのコードをよりモジュール化して整理し、Rustのモジュールを使用します。\n\n\n## モジュール\n\n[モジュール](https://doc.rust-lang.org/rust-by-example/mod.html)は、\nコードの整理に役立ちます。また、関数をモジュールのスコープ内に隠し、main()スコープからのアクセスを制限することも可能です。リーダーアプリケーションでは、RSSフィードのコンテンツを取得し、XMLレスポンスを解析したいため、`main()`\nからは、`get_feeds()` 関数のみにアクセスできるようにし、それ以外の機能はモジュール内のみで使用できるように制限します。\n\n\n`src/` ディレクトリに `feed_reader.rs` という名前の新しいファイルを作成します。コード提案に、`feed_reader`\nという名前の公開モジュールと、String HashMapをインプットとして受け取る `get_feeds()`\nという公開関数を作成するよう指示します。重要：[Rustのモジュール構造](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html)に従って、ファイル名とモジュール名を同じにする必要があります。\n\n\n![コード提案：関数と入力型を使った公開モジュールの作成](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_public_module_function_input.png){:\n.shadow}\n\n\nコード提案に入力変数名と型を指定すると、必要な `std::collections::HashMap`\nモジュールが自動的にインポートされます。ヒント：最適な結果を得られるよう、コメントを使って変数の型を調整してみましょう。また、Rustでは関数のパラメータをオブジェクト参照として渡すのがベストプラクティスとされています。以下に例を示します。\n\n\n```rust\n\n// Create public module feed_reader\n\n// Define get_feeds() function which takes rss_feeds as String HashMap\nreference as input\n\npub mod feed_reader {##$_0A$##    use\nstd::collections::HashMap;##$_0A$####$_0A$##    pub fn get_feeds(rss_feeds:\n&HashMap\u003CString, String>) {##$_0A$##        // Do something with the RSS\nfeeds##$_0A$##    }##$_0A$##}\n\n```\n\n\n![コード提案：`get_feeds()`\n関数と提案された入力変数を含む公開モジュール](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_public_module_function_input.png){:\n.shadow}\n\n\n関数内では、コード提案に以下の手順を指示します。\n\n\n1. `// Iterate over the RSS feed URLs` （RSSフィードURLを反復処理する）\n\n2. `// Fetch URL content` （URLコンテンツを取得する）\n\n3. `// Parse XML body` （XMLの本文を解析する）\n\n4. `// Print the result`  (結果を出力する)\n\n\n![コード提案：`get_feeds()`\n関数を含む公開モジュール、ステップ1：イテレート](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_module_function_01_iterate.png){:\n.shadow}\n\n\n![コード提案：`get_feeds()`\n関数を含む公開モジュール、ステップ2：URLコンテンツの取得](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_module_function_02_fetch_content.png){:\n.shadow}\n\n\n![コード提案：`get_feeds()`\n関数を含む公開モジュール、ステップ3：XML本文の解析](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_module_function_03_parse_body.png){:\n.shadow}\n\n\n![コード提案：`get_feeds()`\n関数を含む公開モジュール、ステップ4：結果の出力](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_module_function_04_print_result.png){:\n.shadow}\n\n\n次のコードが提案されます。\n\n\n```rust\n\n// Create public module feed_reader\n\n// Define get_feeds() function which takes rss_feeds as String HashMap\nreference as input\n\npub mod feed_reader {##$_0A$##    use\nstd::collections::HashMap;##$_0A$####$_0A$##    pub fn get_feeds(rss_feeds:\n&HashMap\u003CString, String>) {##$_0A$##        // Iterate over the RSS feed\nURLs##$_0A$##        for (name, url) in rss_feeds {##$_0A$##           \nprintln!(\"{}: {}\", name, url);##$_0A$####$_0A$##            // Fetch URL\ncontent##$_0A$##            let body =\nreqwest::blocking::get(url).unwrap().text().unwrap();##$_0A$####$_0A$##           \n// Parse XML body##$_0A$##            let parsed_body =\nroxmltree::Document::parse(&body).unwrap();##$_0A$####$_0A$##            //\nPrint the result##$_0A$##            println!(\"{:#?}\",\nparsed_body);##$_0A$##        }##$_0A$##    }##$_0A$##}\n\n```\n\n\nここで新しいキーワード\n[`unwrap()`](https://doc.rust-lang.org/rust-by-example/error/option_unwrap.html)が登場します。Rustは\n`null` 値をサポートしておらず、すべての値に対して [`Option`\n型](https://doc.rust-lang.org/rust-by-example/std/option.html)を使用します。たとえば、`Text`\nや `String` といった特定のラップされた型を使用することが確定している場合、`unwrap()`\nメソッドを呼び出してその値を取得できます。ただし、値が `None` の場合、`unwrap()` メソッドはパニックを起こします。\n\n\n**注意**：コード提案は、`// Fetch URL content` のコメント指示に従って、`reqwest::blocking::get`\n関数を参照します。[`reqwest`](https://docs.rs/reqwest/latest/reqwest/)というクレーと名は意図的なものであり、タイポではありません。非同期リクエストとブロッキングリクエストの処理に役立つ、優れた利便性と高レベルのHTTPクライアントの機能を提供します。\n\n\nXMLの本文の解析は難しく、異なる結果が得られることがあります。また、スキーマはRSSフィードURLごとに異なる可能性があります。まずは\n`get_feeds()` 関数を呼び出し、その後でコードの改善に取り組みましょう。\n\n\n### main() 関数によるモジュール関数の呼び出し\n\n\n現在、main() 関数は `get_feeds()`\n関数を認識していないため、まずそのモジュールをインポートする必要があります。他のプログラミング言語では `include` や `import`\nといったキーワードを目にすることがありますが、Rustのモジュールシステムは異なります。\n\n\nモジュールはパスディレクトリに整理されます。今回の例では、両方のソースファイルが同じディレクトリレベルに存在しています。`feed_reader.rs`\nはクレートとして解釈され、その中に `feed_reader` というモジュールがあり、そのモジュールが `get_feeds()`\n関数を定義しています。\n\n\n```\n\nsrc/\n  main.rs\n  feed_reader.rs\n```\n\n\n`feed_reader.rs` ファイルの `get_feeds()` 関数にアクセスするためには、まず `main.rs`\nのスコープに[モジュールパスを取り込み](https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html)、その後フルパスで関数を呼び出します。\n\n\n```rust\n\nmod feed_reader;\n\n\nfn main() {\n\n    feed_reader::feed_reader::get_feeds(&rss_feeds);\n\n```\n\n\nあるいは、`use` キーワードを使って関数のフルパスをインポートし、その後短い関数名で呼び出すこともできます。\n\n\n```rust\n\nmod feed_reader;\n\nuse feed_reader::feed_reader::get_feeds;\n\n\nfn main() {\n\n    get_feeds(&rss_feeds);\n\n```\n\n\n**ヒント**：Rustのモジュールシステムを視覚的によりよく理解するために、[Rustモジュールシステムについてわかりやすく説明したブログ記事](https://www.sheshbabu.com/posts/rust-module-system/)（英語）をお読みください。\n\n\n```diff\n\n\nfn main() {\n    // ...\n\n    // Print feed_reader get_feeds() output\n    println!(\"{}\", feed_reader::get_feeds(&rss_feeds));\n```\n\n\n```rust\n\nuse std::collections::HashMap;\n\n\nmod feed_reader;\n\n// Alternative: Import full function path\n\n//use feed_reader::feed_reader::get_feeds;\n\n\nfn main() {##$_0A$##    // Define RSS feed URLs in the variable\nrss_feeds##$_0A$##    // Use a HashMap##$_0A$##    // Add Hacker News and\nTechCrunch##$_0A$##    // Ensure to use String as type##$_0A$##    let\nrss_feeds = HashMap::from([##$_0A$##        (\"Hacker News\".to_string(),\n\"https://news.ycombinator.com/rss\".to_string()),##$_0A$##       \n(\"TechCrunch\".to_string(),\n\"https://techcrunch.com/feed/\".to_string()),##$_0A$##   \n]);##$_0A$####$_0A$##    // Call get_feeds() from feed_reader\nmodule##$_0A$##   \nfeed_reader::feed_reader::get_feeds(&rss_feeds);##$_0A$##    // Alternative:\nImported full path, use short path here.##$_0A$##   \n//get_feeds(&rss_feeds);##$_0A$##}\n\n```\n\n\nターミナルで `cargo build` を再実行しコードをビルドします。\n\n\n```shell\n\ncargo build\n\n```\n\n\n以下は、HTTPリクエストやXML解析に関する一般的なコードを参照した際に発生する可能性のあるビルドエラーの例です。\n\n\n1. エラー： `could not find blocking in reqwest`\n\n解決策：`Config.toml` ファイルで `reqwest` クレートの `blocking` 機能を有効にします（`reqwest = {\nversion = \"0.11.20\", features = [\"blocking\"] }`）\n\n2. エラー：`failed to resolve: use of undeclared crate or module reqwest`\n\n解決策：`reqwest` クレートを追加します\n\n3. エラー：`failed to resolve: use of undeclared crate or module roxmltree`\n\n解決策：`roxmltree` クレートを追加します\n\n\n```shell\n\nvim Config.toml\n\n\nreqwest = { version = \"0.11.20\", features = [\"blocking\"] }\n\n```\n\n\n```shell\n\ncargo add reqwest\n\ncargo add roxmltree\n\n```\n\n\n**ヒント**：エラーメッセージの文字列を `Rust \u003Cerror message>`\nとしてブラウザで検索し、欠落しているクレートが利用可能であるかどうか確認しましょう。通常、検索結果に「crates.io」が表示され、そこから不足している依存関係を追加できます。\n\n\nビルドが成功したら、`cargo run` でコードを実行し、Hacker NewsのRSSフィードの出力を確認します。\n\n\n![VS Codeのターミナルでcargo runを実行して、Hacker\nNewsのXMLフィードを取得](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_fetch_rss_feed_output_hacker_news.png){:\n.shadow}\n\n\nXML本文を人間が読める形式に解析するにはどうすればいいでしょうか？次のセクションでは、既存の解決策とRustのクレートがどのように機能するかを説明します。\n\n\n## クレート\n\nRSSフィードは共通のプロトコルと仕様に基づいており、XMLを解析して下位のオブジェクト構造を理解するのは、例えば車輪のように、すでに存在しているものを再び深く掘り下げて再発明するかのようです。。こういったタスクに対するおすすめのアプローチは、過去に同じ問題に直面した人がいないか、また、その問題を解決するためのコードがすでに作られていないかを調べることです。\n\n\nRustでの再利用可能なライブラリコードは\n[`Crates`](https://doc.rust-lang.org/rust-by-example/crates.html)と呼ばれる単位で整理され、パッケージで提供されます。これらはcrates.ioのパッケージレジストリで利用可能です。これらの依存関係をプロジェクトに追加するには、`Config.toml`\nファイルの `[dependencies]` セクションを編集するか、`cargo add \u003Cname>` コマンドを使用します。\n\n\nリーダーアプリケーションでは、[feed-rs\nクレート](https://crates.io/crates/feed-rs)を使用したいため、新しいターミナルを開き、次のコマンドを実行してください。\n\n\n```shell\n\ncargo add feed-rs\n\n```\n\n\n![VS\nCodeのターミナル：クレートを追加し、Config.tomlで確認](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_rust_crate_add_feed-rs_explained.png)\n\n\n### feed-rs：XMLフィードの解析\n\n`src/feed_reader.rs` に移動し、XML本文を解析する部分に対して修正を加えます。コード提案は、`feed-rs` クレートの\n`parser::parse` 関数をどのように呼び出すか理解していますが、ひとつだけ特別な点があります。`feed-rs`\nは文字列をrawバイトとして入力し、自らエンコーディングを判断します。ただし、コメントに指示を追加することで、期待の結果を得ることは可能です。\n\n\n```rust\n            // Parse XML body with feed_rs parser, input in bytes\n            let parsed_body = feed_rs::parser::parse(body.as_bytes()).unwrap();\n```\n\n\n![コード提案：`get_feeds()`\n関数を含む公開モジュール、ステップ5：XMLパーサーをfeed-rsに変更](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_module_function_05_use_feed_rs_to_parse.png){:\n.shadow}\n\n\n`feed-rs` を使用するメリットは即座に可視化できるものでなく、`cargo run`\nで出力を確認するとその効果が明らかになります。すべてのキーと値がそれぞれのRustオブジェクト型にマッピングされ、さらに高度な処理に利用できるようになります。\n\n\n![VS Codeのターミナル、cargo runを実行してHacker\nNewsのXMLフィードを取得](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_fetch_rss_feed_output_hacker_news_feed_rs.png){:\n.shadow}\n\n\n## ランタイム設定：プログラム引数\n\nここまで、コンパイル時にバイナリに埋め込まれ、ハードコードされたRSSフィードの値を使用してプログラムを実行してきました。次のステップでは、実行時にRSSフィードを設定できるようにします。\n\n\nRustでは、標準miscライブラリに[プログラム引数](https://doc.rust-lang.org/rust-by-example/std_misc/arg.html)を処理するための機能が用意されています。[プログラム引数を解析](https://doc.rust-lang.org/rust-by-example/std_misc/arg/matching.html)することで、高度なプログラム引数パーサー（たとえば[clap](https://docs.rs/clap/latest/clap/)クレート）を使用したり、プログラムパラメータを構成ファイルやフォーマット（[TOML](https://toml.io/en/)やYAML）に移したりするよりも、簡単かつ効率的に学習を進めることができます。実際にいくつかの方法を試した結果、学習効果を最大限に高めるには、この方法が最適であると判断しましたが、唯一の方法ではありません。他の方法でRSSフィードの設定を試してみる価値もあります。\n\n\n単純な解決策としては、コマンドパラメータを `\"name,url\"` の文字列ペアとして渡してから、`,`\nで分割して名前とURLの値を抽出します。コード提案に、これらの操作を実行して新しい値で `rss_feeds`\nハッシュマップを拡張するようコメントで指示します。変数が変更可能でない可能性があるため、`let rss_feeds` を `let mut\nrss_feeds` に変更する必要がある点にご注意ください。\n\n\n`src/main.rs` に移動し、`rss_feeds` 変数の後に次のコードを `main()`\n関数の追加します。まずはコメントでプログラム引数を定義し、提案されたコードスニペットを確認します。\n\n\n```rust\n    // Program args, format \"name,url\"\n    // Split value by , into name, url and add to rss_feeds\n```\n\n\n![プログラム引数に関するコード提案、および rss_feeds\n変数のために名前とURLの値を分割するコード提案](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_program_args_boring_solution.png){:\n.shadow}\n\n\nコード全体の例は次のようになります。\n\n\n```rust\n\nfn main() {##$_0A$##    // Define RSS feed URLs in the variable\nrss_feeds##$_0A$##    // Use a HashMap##$_0A$##    // Add Hacker News and\nTechCrunch##$_0A$##    // Ensure to use String as type##$_0A$##    let mut\nrss_feeds = HashMap::from([##$_0A$##        (\"Hacker News\".to_string(),\n\"https://news.ycombinator.com/rss\".to_string()),##$_0A$##       \n(\"TechCrunch\".to_string(),\n\"https://techcrunch.com/feed/\".to_string()),##$_0A$##   \n]);##$_0A$####$_0A$##    // Program args, format \"name,url\"##$_0A$##    //\nSplit value by , into name, url and add to rss_feeds##$_0A$##    for arg in\nstd::env::args().skip(1) {##$_0A$##        let mut split =\narg.split(\",\");##$_0A$##        let name =\nsplit.next().unwrap();##$_0A$##        let url =\nsplit.next().unwrap();##$_0A$##        rss_feeds.insert(name.to_string(),\nurl.to_string());##$_0A$##    }##$_0A$####$_0A$##    // Call get_feeds()\nfrom feed_reader module##$_0A$##   \nfeed_reader::feed_reader::get_feeds(&rss_feeds);##$_0A$##    // Alternative:\nImported full path, use short path here.##$_0A$##   \n//get_feeds(&rss_feeds);##$_0A$##}\n\n```\n\n\nプログラムの引数を `cargo run` コマンドに直接渡すことができます。その際は引数の前に `--`をつけます。\nすべての引数をダブルクォートで囲み、名前の後にカンマを付けてRSSフィードのURLを引数として渡します。引数は空白で区切ります。\n\n\n```\n\ncargo build\n\n\ncargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n```\n\n\n![VS\nCodeターミナル、GitLabブログのRSSフィード出力例](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_gitlab_blog_rss_feed_example.png){:\n.shadow}\n\n\n### ユーザー入力のエラーハンドリング\n\n提供されたユーザー入力がプログラムで想定される内容と異なる場合、[エラーを発生](https://doc.rust-lang.org/rust-by-example/error.html)させ、呼び出し元がプログラム引数を修正できるようにする必要があります。たとえば、不正なURL形式が渡された場合、それをランタイムエラーとして処理する必要があります。コード提案に対し、URLが無効な場合はエラーをスローするようコメントで指示します。\n\n\n```rust\n    // Ensure that URL contains a valid format, otherwise throw an error\n```\n\n\nひとつの解決策として、`url` 変数が `http://` または `https://` で始まっているかを確認し、そうでなければ [panic!\nマクロ](https://doc.rust-lang.org/rust-by-example/std/panic.html)を使ってエラーをスローする方法があります。コード全体の例は次のようになります。\n\n\n```rust\n    // Program args, format \"name,url\"\n    // Split value by , into name, url and add to rss_feeds\n    for arg in std::env::args().skip(1) {\n        let mut split = arg.split(\",\");\n        let name = split.next().unwrap();\n        let url = split.next().unwrap();\n\n        // Ensure that URL contains a valid format, otherwise throw an error\n        if !url.starts_with(\"http://\") && !url.starts_with(\"https://\") {\n            panic!(\"Invalid URL format: {}\", url);\n        }\n\n        rss_feeds.insert(name.to_string(), url.to_string());\n    }\n```\n\n\n任意のURL文字列から `:` を削除してエラーハンドリングをテストします。`RUST_BACKTRACE=full`\n環境変数を追加すると、`panic()` 呼び出しが発生した際に詳細な出力を取得できます。\n\n\n```\n\nRUST_BACKTRACE=full cargo run -- \"GitLab\nBlog,https://about.gitlab.com/atom.xml\" \"CNCF,https//www.cncf.io/feed/\"\n\n```\n\n\n![間違ったURL形式によるパニックエラーのバックトレースが表示されたVS\nCodeターミナル](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_url_format_error_panic_backtrace.png){:\n.shadow}\n\n\n## 永続性とデータ保存\n\nフィードデータを保存する単純な解決策は、解析されたデータを新しいファイルに書き出すことです。コード提案に、RSSフィードの名前と現在のISO日付を含むパターンでファイルを保存するよう指示します。\n\n\n```rust\n    // Parse XML body with feed_rs parser, input in bytes\n    let parsed_body = feed_rs::parser::parse(body.as_bytes()).unwrap();\n\n    // Print the result\n    println!(\"{:#?}\", parsed_body);\n\n    // Dump the parsed body to a file, as name-current-iso-date.xml\n    let now = chrono::offset::Local::now();\n    let filename = format!(\"{}-{}.xml\", name, now.format(\"%Y-%m-%d\"));\n    let mut file = std::fs::File::create(filename).unwrap();\n    file.write_all(body.as_bytes()).unwrap();\n```\n\n\nこの処理の一例として、[chronoクレート](https://crates.io/crates/chrono)を使用する方法があります。`cargo\nadd chrono` を実行して追加し、その後 `cargo build` と `cargo run` を再度実行します。\n\n\nファイルは `cargo run` が実行されたディレクトリに保存されます。バイナリを `target/debug/`\nディレクトリで直接実行している場合、すべてのファイルはそのディレクトリにダンプされます。\n\n\n![CNCFのRSSフィード内容を含むファイルがディスクに保存された状態のVS Code](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_cncf_rss_feed_saved_on_disk.png)\n\n\n## 最適化\n\n`rss_feeds`\n変数内のエントリは逐次実行されています。もし100件以上のURLがリストに設定されている場合、データの取得と処理にはかなりの時間がかかるでしょう。複数のフェッチリクエストを並行して実行できたらどうでしょうか？\n\n\n### 非同期実行\n\nRustでは、[スレッド](https://doc.rust-lang.org/book/ch16-01-threads.html)を使用した非同期実行が可能です。\n\n\n最も簡単な解決策は、各RSSフィードURLごとにスレッドを生成することです。最適化戦略については後のセクションで説明します。並行実行を開始する前に、\n`time` コマンドの前に`cargo run` をつけて、逐次実行コードの実行時間を測定しましょう。\n\n\n```\n\ntime cargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n\n0.21s user 0.08s system 10% cpu 2.898 total\n\n```\n\n\nなお、この演習では、手動のコーディング作業が多くなる場合があります。並列実行の影響をより効果的に比較するには、逐次実行の動作状態を新しいGitコミットとブランチ\n`sequential-exec` に保存してください。\n\n```shell\n\ngit commit -avm \"Sequential execution working\"\n\ngit checkout -b sequential-exec\n\ngit push -u origin sequential-exec\n\n\ngit checkout main\n\n```\n\n\n### スレッドの生成\n\n`src/feed_reader.rs` を開き、`get_feeds()`\n関数をリファクタリングします。まず、現在の状態をGitコミットで保存し、その後、関数のスコープ内の内容を削除します。次に、コード提案への指示と以下のコードコメントを入力します。\n\n\n1. `// Store threads in\nvector`：スレッドのハンドルをベクターに格納し、関数呼び出しの最後にスレッドが終了するまで待機できるようにします。\n\n2. `// Loop over rss_feeds and spawn\nthreads`：すべてのRSSフィードを反復処理するためのコードを作成し、新しいスレッドを作成します。\n\n\n`thread` モジュールと `time` モジュールを扱うには、次の `use` 文を追加します。\n\n\n```rust\n    use std::thread;\n    use std::time::Duration;\n```\n\n\nその後、forループを閉じるまでコードを書き進めます。コード提案は、自動的にスレッドハンドルを `threads`\nベクター変数に追加し、関数の最後でスレッドを結合（join）するよう提案します。\n\n\n```rust\n    pub fn get_feeds(rss_feeds: &HashMap\u003CString, String>) {\n\n        // Store threads in vector\n        let mut threads: Vec\u003Cthread::JoinHandle\u003C()>> = Vec::new();\n\n        // Loop over rss_feeds and spawn threads\n        for (name, url) in rss_feeds {\n            let thread_name = name.clone();\n            let thread_url = url.clone();\n            let thread = thread::spawn(move || {\n\n            });\n            threads.push(thread);\n        }\n\n        // Join threads\n        for thread in threads {\n            thread.join().unwrap();\n        }\n    }\n```\n\n\n次に、`thread` クレートを追加し、もう一度コードをビルドし実行します。\n\n\n```shell\n\ncargo add thread\n\n\ncargo build\n\n\ncargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n```\n\n\nこの段階では、データの処理や出力は行われていません。次のステップに移る前に、ここで新たに導入されたキーワードについて解説します。\n\n\n### 関数スコープ、スレッド、クロージャ\n\n提案されるコードには新しいキーワードやデザインパターンが含まれることもあるため、これらについて理解しておくことが重要になります。スレッドハンドルは\n`thread::JoinHandle`\nという型で、スレッドが終わるのを待機するために使用します（[join()](https://doc.rust-lang.org/book/ch16-01-threads.html#waiting-for-all-threads-to-finish-using-join-handles)メソッドを使います）。\n\n\n`thread::spawn()`\nは新しいスレッドを生成し、このスレッド内では、関数オブジェクトを渡すことができます。この場合、[クロージャ](https://doc.rust-lang.org/book/ch13-01-closures.html)式が無名関数として渡されます。また、クロージャ入力は\n`||` 構文を使用して渡されますが、この際には[`move`\nクロージャ](https://doc.rust-lang.org/book/ch16-01-threads.html#using-move-closures-with-threads)が関数スコープの変数をスレッドスコープに移動します。これにより、どの変数を新しい関数やクロージャスコープに渡すかを手動で指定する必要がなくなります。\n\n\nただし、これには制限があります。`rss_feeds` は参照 `&` で、`get_feeds()`\n関数の呼び出し元からパラメータとして渡されています。この変数は関数スコープ内でのみ有効です。このエラーを引き起こすには、次のコードスニペットを使用します。\n\n\n```rust\n\npub fn get_feeds(rss_feeds: &HashMap\u003CString, String>) {##$_0A$####$_0A$##   \n// Store threads in vector##$_0A$##    let mut threads:\nVec\u003Cthread::JoinHandle\u003C()>> = Vec::new();##$_0A$####$_0A$##    // Loop over\nrss_feeds and spawn threads##$_0A$##    for (key, value) in rss_feeds\n{##$_0A$##        let thread = thread::spawn(move || {##$_0A$##           \nprintln!(\"{}\", key);##$_0A$##        });##$_0A$##    }##$_0A$##}\n\n```\n\n\n![VS Codeターミナル、参照とスレッドのmoveクロージャに関する変数スコープエラー](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_cargo_build_error_function_threads_variable_scopes.png){:\n.shadow}\n\n\n`key` 変数は関数スコープ内で作成されていますが、`rss_feeds`\n変数を参照しているため、スレッドスコープに移動することはできません。関数パラメータ `rss_feeds`\nのハッシュマップからアクセスされる値は、`clone()` を使ってローカルコピーを作成する必要があります。\n\n\n![VS\nCodeターミナル、cloneを使用したスレッドの生成](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_rust_thread_spawn_clone.png){:\n.shadow}\n\n\n```rust\n\npub fn get_feeds(rss_feeds: &HashMap\u003CString, String>) {\n\n    // Store threads in vector\n    let mut threads: Vec\u003Cthread::JoinHandle\u003C()>> = Vec::new();\n\n    // Loop over rss_feeds and spawn threads\n    for (name, url) in rss_feeds {\n        let thread_name = name.clone();\n        let thread_url = url.clone();\n        let thread = thread::spawn(move || {\n            // Use thread_name and thread_url as values, see next chapter for instructions.\n```\n\n\n## フィードのXMLの解析およびオブジェクト型への変換\n\n次のステップは、スレッド内のクロージャでRSSフィードの解析手順を繰り返すことです。コード提案の指示とともに以下のコードコメントを追加します。\n\n\n1. `// Parse XML body with feed_rs parser, input in\nbytes`：コード提案に対し、RSSフィードのURLコンテンツを取得し、`feed_rs` クレートの関数で解析したいという要望を伝えます。\n\n2. `// Check feed_type attribute feed_rs::model::FeedType::RSS2 or Atom and\nprint its name`：`feed_type` 属性を\n[`feed_rs::model::FeedType`](https://docs.rs/feed-rs/latest/feed_rs/model/enum.FeedType.html)\nと照合してフィードの種類を抽出します。この場合、コード提案に対して、照合の対象とする正確なEnum値を指示する必要があります。\n\n\n![コード提案に特定のフィードタイプと照合するよう指示](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_feed_rs_type_condition.png){:\n.shadow}\n\n\n```rust\n            // Parse XML body with feed_rs parser, input in bytes\n            let body = reqwest::blocking::get(thread_url).unwrap().bytes().unwrap();\n            let feed = feed_rs::parser::parse(body.as_ref()).unwrap();\n\n            // Check feed_type attribute feed_rs::model::FeedType::RSS2 or Atom and print its name\n            if feed.feed_type == feed_rs::model::FeedType::RSS2 {\n                println!(\"{} is an RSS2 feed\", thread_name);\n            } else if feed.feed_type == feed_rs::model::FeedType::Atom {\n                println!(\"{} is an Atom feed\", thread_name);\n            }\n```\n\n\nプログラムをもう一度ビルドして実行し、出力を確認します。\n\n\n```\n\ntime cargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n\nCNCF is an RSS2 feed\n\nTechCrunch is an RSS2 feed\n\nGitLab Blog is an Atom feed\n\nHacker News is an RSS2 feed\n\n```\n\n\nフィードURLをブラウザで開くか、以前にダウンロードしたファイルを調べて、この出力を確認します。\n\n\nHacker News はRSS\n2.0をサポートしており、`channel(title,link,description,item(title,link,pubDate,comments))`\nの構造を持っています。TechCrunchとCNCFブログは同様の構造をしています。\n\n```xml\n\n\u003Crss version=\"2.0\">\u003Cchannel>\u003Ctitle>Hacker\nNews\u003C/title>\u003Clink>https://news.ycombinator.com/\u003C/link>\u003Cdescription>Links for\nthe intellectually curious, ranked by\nreaders.\u003C/description>\u003Citem>\u003Ctitle>Writing a debugger from scratch:\nBreakpoints\u003C/title>\u003Clink>https://www.timdbg.com/posts/writing-a-debugger-from-scratch-part-5/\u003C/link>\u003CpubDate>Wed,\n27 Sep 2023 06:31:25\n+0000\u003C/pubDate>\u003Ccomments>https://news.ycombinator.com/item?id=37670938\u003C/comments>\u003Cdescription>\u003C![CDATA[\u003Ca\nhref=\"https://news.ycombinator.com/item?id=37670938\">Comments\u003C/a>]]>\u003C/description>\u003C/item>\u003Citem>\n\n```\n\n\nGitLabブログには[Atom](https://datatracker.ietf.org/doc/html/rfc4287)フィード形式が使用されています。RSSに類似していますが異なる解析ロジックが必要です。\n\n```xml\n\n\u003C?xml version='1.0' encoding='utf-8' ?>\n\n\u003Cfeed xmlns='http://www.w3.org/2005/Atom'>\n\n\u003C!-- / Get release posts -->\n\n\u003C!-- / Get blog posts -->\n\n\u003Ctitle>GitLab\u003C/title>\n\n\u003Cid>https://about.gitlab.com/blog\u003C/id>\n\n\u003Clink href='https://about.gitlab.com/blog/' />\n\n\u003Cupdated>2023-09-26T00:00:00+00:00\u003C/updated>\n\n\u003Cauthor>\n\n\u003Cname>The GitLab Team\u003C/name>\n\n\u003C/author>\n\n\u003Centry>\n\n\u003Ctitle>Atlassian Server ending: Goodbye disjointed toolchain, hello\nDevSecOps platform\u003C/title>\n\n\u003Clink\nhref='https://about.gitlab.com/blog/atlassian-server-ending-move-to-a-single-devsecops-platform/'\nrel='alternate' />\n\n\u003Cid>https://about.gitlab.com/blog/atlassian-server-ending-move-to-a-single-devsecops-platform/\u003C/id>\n\n\u003Cpublished>2023-09-26T00:00:00+00:00\u003C/published>\n\n\u003Cupdated>2023-09-26T00:00:00+00:00\u003C/updated>\n\n\u003Cauthor>\n\n\u003Cname>Dave Steer, Justin Farris\u003C/name>\n\n\u003C/author>\n\n```\n\n\n### 汎用的なフィードデータ型のマッピング\n\n[`roxmltree::Document::parse`](https://docs.rs/roxmltree/latest/roxmltree/struct.Document.html)\nを使用する場合、XMLノードツリーとその特定のタグ名を理解する必要があります。幸い、[`feed_rs::model::Feed`](https://docs.rs/feed-rs/latest/feed_rs/model/struct.Feed.html)\nはRSSとAtomフィードの統合モデルを提供しているため、引き続き `feed_rs` クレートを使用して進めましょう。\n\n\n1. Atom：Feed->Feed、Entry->Entry\n\n2. RSS：Channel->Feed、Item->Entry\n\n\n上記のマッピングに加えて、必要な属性を抽出し、それらのデータ型をマッピングする必要があります。[feed_rs::modelのドキュメント](https://docs.rs/feed-rs/latest/feed_rs/model/index.html)を開き、構造体やそのフィールド、実装について理解しながら進めることをお勧めします。これは、`feed_rs`\nの実装に特有の型変換エラーやコンパイルエラーが発生するのを防ぐためです。\n\n\n[`Feed`](https://docs.rs/feed-rs/latest/feed_rs/model/struct.Feed.html) 構造体は\n`title` を提供しますが、その型は `Option\u003CText>`\nで、値が設定されているか、何もないかのいずれかです。[`Entry`](https://docs.rs/feed-rs/latest/feed_rs/model/struct.Entry.html)\n構造体は以下の情報を提供します。\n\n\n1. `title`：`Option\u003CText>`\n型で、[`Text`](https://docs.rs/feed-rs/latest/feed_rs/model/struct.Text.html)\nには `content` フィールドが `String` 型として含まれています。\n\n2. `published`：`Option\u003CDateTime\u003CUtc>>`\n型で、[`DateTime`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html) は\n[`format()`\nメソッド](https://docs.rs/chrono/latest/chrono/struct.DateTime.html#method.format)を持ちます。\n\n3. `summary`：`Option\u003CText>` \n型で、[`Text`](https://docs.rs/feed-rs/latest/feed_rs/model/struct.Text.html)\nには `content` フィールドが `String` 型として含まれています。\n\n4. `links`：`Vec\u003CLink>`\n型で、[`Link`](https://docs.rs/feed-rs/latest/feed_rs/model/struct.Link.html)\n項目のベクターです。`href` 属性が生のURL文字列を提供します。\n\n\n1から4に従って、フィードエントリから必要なデータを抽出します。繰り返しますが、すべての `Option` 型には `unwrap()`\nを呼び出す必要があります。このため、コード提案に対してより直接的な指示が求められます。\n\n\n```rust\n                // https://docs.rs/feed-rs/latest/feed_rs/model/struct.Feed.html\n                // https://docs.rs/feed-rs/latest/feed_rs/model/struct.Entry.html\n                // Loop over all entries, and print\n                // title.unwrap().content\n                // published.unwrap().format\n                // summary.unwrap().content\n                // links href as joined string\n                for entry in feed.entries {\n                    println!(\"Title: {}\", entry.title.unwrap().content);\n                    println!(\"Published: {}\", entry.published.unwrap().format(\"%Y-%m-%d %H:%M:%S\"));\n                    println!(\"Summary: {}\", entry.summary.unwrap().content);\n                    println!(\"Links: {:?}\", entry.links.iter().map(|link| link.href.clone()).collect::\u003CVec\u003CString>>().join(\", \"));\n                    println!();\n                }\n```\n\n\n![特定の要件に基づいてフィードエントリの型を出力するためのコード提案](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_print_feed_entries_fields_with_rust_type_specifics.png){:\n.shadow}\n\n\n### Option::unwrap()によるエラーハンドリング\n\nプログラムを再ビルドして実行した後、複数行の指示を引き続き処理します。補足：`unwrap()` は空の値に遭遇すると `panic!`\nマクロを呼び出し、プログラムを強制終了させます。これは、フィードデータ内に `summary` のようなフィールドが設定されていない場合に発生します。\n\n\n```shell\n\nGitLab Blog is an Atom feed\n\nTitle: How the Colmena project uses GitLab to support citizen journalists\n\nPublished: 2023-09-27 00:00:00\n\nthread '\u003Cunnamed>' panicked at 'called `Option::unwrap()` on a `None`\nvalue', src/feed_reader.rs:40:59\n\n```\n\n\n解決策のひとつとして、[`std::Option::unwrap_or_else`](https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or_else)\nを使用し、デフォルト値として空の文字列を設定することが挙げられます。この構文には、空の `Text` 構造体のインスタンスを返すクロージャが必要です。\n\n\n問題を解決する上で、正しい初期化方法を見つけるために試行錯誤を重ねました。単に空の文字列を渡すだけではカスタム型ではうまく機能しませんでした。以下に、筆者が試したすべてのアプローチとリサーチの過程をまとめました。\n\n\n```rust\n\n// Problem: The `summary` attribute is not always initialized. unwrap() will\npanic! then.\n\n// Requires use mime; and use feed_rs::model::Text;\n\n/*\n\n// 1st attempt: Use unwrap() to extraxt Text from Option\u003CText> type.\n\nprintln!(\"Summary: {}\", entry.summary.unwrap().content);\n\n// 2nd attempt. Learned about unwrap_or_else, passing an empty string.\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| \"\").content);\n\n// 3rd attempt. summary is of the Text type, pass a new struct\ninstantiation.\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{}).content);\n\n// 4th attempt. Struct instantiation requires 3 field values.\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{\"\", \"\",\n\"\"}).content);\n\n// 5th attempt. Struct instantation with public fields requires key: value\nsyntax\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{content_type:\n\"\", src: \"\", content: \"\"}).content);\n\n// 6th attempt. Reviewed expected Text types in\nhttps://docs.rs/feed-rs/latest/feed_rs/model/struct.Text.html and created\nMime and String objects\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{content_type:\nmime::TEXT_PLAIN, src: String::new(), content: String::new()}).content);\n\n// 7th attempt: String and Option\u003CString> cannot be casted automagically.\nCompiler suggested using `Option::Some()`.\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{content_type:\nmime::TEXT_PLAIN, src: Option::Some(), content: String::new()}).content);\n\n*/\n\n\n// xth attempt: Solution. Option::Some() requires a new String object.\n\nprintln!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{content_type:\nmime::TEXT_PLAIN, src: Option::Some(String::new()), content:\nString::new()}).content);\n\n```\n\n\nこのアプローチは、コードが複雑で読みにくく、さらにコード提案の支援がなかったため、手動でコーディングする必要があり、満足のいくものではありませんでした。一旦立ち止まり、アプローチを見直しました。`Option`\nが `none` の場合に`unwrap()`\nはエラーをスローするのであれば、そのエラーを処理する簡単な方法があるのではと考え、コード提案に新しいコメントで質問しました。\n\n\n```\n                // xth attempt: Solution. Option::Some() requires a new String object.\n                println!(\"Summary: {}\", entry.summary.unwrap_or_else(|| Text{content_type: mime::TEXT_PLAIN, src: Option::Some(String::new()), content: String::new()}).content);\n\n                // Alternatively, use Option.is_none()\n```\n\n\n![コード提案によるOptions.is_noneを使った代替案](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/code_suggestions_after_complex_unwrap_or_else_ask_for_alternative_option.png){:\n.shadow}\n\n\n結果として、読みやすさが向上し、`unwrap()`\nによる無駄なCPUサイクルが減りました。複雑な問題を解決することから単純な解決策を使用することまでの学習過程を大幅に短縮できました。まさにウィンウィンです。\n\n\n忘れないうちに、XMLデータをディスクに保存する指示を再度追加して、リーダーアプリを完成させましょう。\n\n\n```rust\n                // Dump the parsed body to a file, as name-current-iso-date.xml\n                let file_name = format!(\"{}-{}.xml\", thread_name, chrono::Local::now().format(\"%Y-%m-%d-%H-%M-%S\"));\n                let mut file = std::fs::File::create(file_name).unwrap();\n                file.write_all(body.as_ref()).unwrap();\n```\n\n\nプログラムをビルドして実行し、出力を確認します。\n\n\n```shell\n\ncargo build\n\n\ntime cargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n```\n\n\n![VS Codeターミナルでcargo\nrunを実行し、フォーマットされたフィードエントリの出力](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/vs_code_terminal_cargo_run_formatted_output_final.png)\n\n\n## ベンチマーク\n\n\n### 逐次実行と並列実行のベンチマークの比較\n\nそれぞれ5つのサンプルを作成して、実行時間のベンチマークを比較します。\n\n\n1. 逐次実行\n\n2. 並列実行\n\n\n```shell\n\n# Sequential\n\ngit checkout sequential-exec\n\n\ntime cargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n\n0.21s user 0.08s system 10% cpu 2.898 total\n\n0.21s user 0.08s system 11% cpu 2.585 total\n\n0.21s user 0.09s system 10% cpu 2.946 total\n\n0.19s user 0.08s system 10% cpu 2.714 total\n\n0.20s user 0.10s system 10% cpu 2.808 total\n\n```\n\n\n```shell\n\n# Parallel\n\ngit checkout parallel-exec\n\n\ntime cargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\"\n\"CNCF,https://www.cncf.io/feed/\"\n\n\n0.19s user 0.08s system 17% cpu 1.515 total\n\n0.18s user 0.08s system 16% cpu 1.561 total\n\n0.18s user 0.07s system 17% cpu 1.414 total\n\n0.19s user 0.08s system 18% cpu 1.447 total\n\n0.17s user 0.08s system 16% cpu 1.453 total\n\n```\n\n\n4つのRSSフィードスレッドを並列実行した場合、CPU使用率は増加しましたが、逐次実行に比べて全体の実行時間はほぼ半減しました。この点を踏まえて、Rustの学習を続け、コードと機能を最適化していきます。\n\n\nなお、ここではCargoを使ってデバッグビルドを実行しており、最適化されたリリースビルドはまだ実行していません。また、並列実行にはいくつか注意点があります。一部のHTTPエンドポイントはレート制限を設けており、並列処理がこの制限に引っかかりやすくなる可能性があります。\n\n\n複数のスレッドを並列実行するシステムも過負荷になる可能性があります。これは、カーネル内でのコンテキストスイッチ（スレッド間の切り替え）を通じて各スレッドにリソースを割り当てる必要があるためです。1つのスレッドが計算リソースを使用している間、他のスレッドは待機状態になります。スレッドが多すぎると、システム全体が遅くなり、処理がスピードアップするどころか逆に遅くなることもあります。解決策としては、呼び出し元がキューにタスクを追加し、定義された数のワーカースレッドが非同期実行のためにタスクを処理する[ワークキュー](https://docs.rs/work-queue/latest/work_queue/)などの設計パターンがあります。\n\n\nRustでは、スレッド間のデータ同期を行う[チャンネル](https://doc.rust-lang.org/rust-by-example/std_misc/channels.html)を利用することもできます。競合状態を防ぐために、セーフロックを提供する[ミューテックス](https://doc.rust-lang.org/std/sync/struct.Mutex.html)も利用可能です。\n\n\n### Rustのキャッシュを使用したCI/CD\n\n以下のCI/CD構成を `.gitlab-ci.yml` ファイルに追加します。この `run-latest` ジョブは `cargo run`\nをRSSフィードURLの例とともに呼び出し、実行時間を継続的に計測します。\n\n\n```\n\nstages:\n  - build\n  - test\n  - run\n\ndefault:\n  image: rust:latest\n  cache:\n    key: ${CI_COMMIT_REF_SLUG}\n    paths:\n      - .cargo/bin\n      - .cargo/registry/index\n      - .cargo/registry/cache\n      - target/debug/deps\n      - target/debug/build\n    policy: pull-push\n\n# Cargo data needs to be in the project directory for being cached.\n\nvariables:\n  CARGO_HOME: ${CI_PROJECT_DIR}/.cargo\n\nbuild-latest:\n  stage: build\n  script:\n    - cargo build --verbose\n\ntest-latest:\n  stage: build\n  script:\n    - cargo test --verbose\n\nrun-latest:\n  stage: run\n  script:\n    - time cargo run -- \"GitLab Blog,https://about.gitlab.com/atom.xml\" \"CNCF,https://www.cncf.io/feed/\"\n```\n\n\n![Rust用のGitLab CI/CDパイプライン、cargo\nrunの出力](https://about.gitlab.com/images/blogimages/learn-rust-with-ai-code-suggestions-advanced-programming/gitlab_cicd_pipeline_rust_cargo_run_output.png){:\n.shadow}\n\n\n## 次のステップ\n\nこのブログ記事の執筆は、筆者自身が高度なRustプログラミング技術を学びつつ、コード提案を使って最適な学習過程を見出すという点で難しいものでした。コード提案は、単なる定型的なコードだけでなく、ローカルコンテキストを理解し、記述されたコードが多いほどアルゴリズムの目的や範囲をよりよく把握した迅速なコード生成にも大いに役立ちます。このブログ記事を読むことで、全てではないにしろ、いくつかの課題や解決策についてご理解いただけたかと思います。\n\n\nRSSフィードの解析は、外部HTTPリクエストや並列最適化を伴うデータ構造が関わるため、ハードルが高めです。経験豊富なRustユーザーであれば、`なぜstd::rssクレートを使わなかったのか？`\nと疑問に思うかもしれません。その理由は、std::rssは高度な非同期実行に最適化されており、このブログ記事でご説明したさまざまなRustの機能を示したり説明したりすることができないためです。ぜひ、非同期の演習として、[`rss`\nクレート](https://docs.rs/rss/latest/rss/)を使ってコードを書き直してみてください。\n\n\n### 非同期学習のエクササイズ\n\nこのブログ記事で学んだ内容は、永続的なデータ保存やデータ表示に関する理解を今後も深めていく上で基礎となります。引き続きRustを学びながら、リーダーアプリを最適化していくためのアイデアをいくつかご紹介します。\n\n\n1. データ保存：sqliteなどのデータベースを使用し、RSSフィードの更新履歴を追跡する。\n\n2. 通知：子プロセスを生成して、Telegramなどに通知を送る機能を追加する。\n\n3. 機能：リーダータイプを拡張して、REST APIをサポートする。\n\n4. 構成：RSSフィードやAPIなどの構成ファイルのサポートを追加する。\n\n5. 効率性：フィルタリングやサブスクライブしたタグのサポートを追加する。\n\n6.\nデプロイ：Webサーバーを使用して、Prometheusメトリクスを収集して[Kubernetes](https://about.gitlab.com/ja-jp/blog/what-is-kubernetes/)にデプロイする。\n\n\n今後のブログ記事では、これらのアイデアのいくつかを取り上げ、その実装方法について説明します。既存のRSSフィードの実装を詳しく調べ、どのように既存のコードをリファクタリングしてRustのライブラリ（`crates`）を活用できるか学びましょう。\n\n\n### フィードバックの共有\n\n[GitLab\nDuo](https://about.gitlab.com/ja-jp/gitlab-duo/)のコード提案をご使用になった方は、ぜひ[ご意見をフィードバックイシューにお寄せください](https://gitlab.com/gitlab-org/gitlab/-/issues/405152)。\n\n\n*監修：佐々木 直晴 [@naosasaki](https://gitlab.com/naosasaki) \u003Cbr>\n\n（GitLab合同会社 ソリューションアーキテクト本部 シニアソリューションアーキテクト）*\n","ai-ml",[23,24,25,26,27],"DevSecOps","careers","tutorial","workflow","AI/ML","2025-01-24",{"slug":30,"featured":6,"template":31},"learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions","BlogPost","content:ja-jp:blog:learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions.yml","yaml","Learn Advanced Rust Programming With A Little Help From Ai Code Suggestions","content","ja-jp/blog/learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions.yml","ja-jp/blog/learn-advanced-rust-programming-with-a-little-help-from-ai-code-suggestions","yml",{"_path":40,"_dir":41,"_draft":6,"_partial":6,"_locale":7,"data":42,"_id":450,"_type":33,"title":451,"_source":35,"_file":452,"_stem":453,"_extension":38},"/shared/ja-jp/main-navigation","ja-jp",{"logo":43,"freeTrial":48,"sales":53,"login":58,"items":63,"search":394,"minimal":428,"duo":441},{"config":44},{"href":45,"dataGaName":46,"dataGaLocation":47},"/ja-jp/","gitlab logo","header",{"text":49,"config":50},"無料トライアルを開始",{"href":51,"dataGaName":52,"dataGaLocation":47},"https://gitlab.com/-/trial_registrations/new?glm_source=about.gitlab.com&glm_content=default-saas-trial/","free trial",{"text":54,"config":55},"お問い合わせ",{"href":56,"dataGaName":57,"dataGaLocation":47},"/ja-jp/sales/","sales",{"text":59,"config":60},"サインイン",{"href":61,"dataGaName":62,"dataGaLocation":47},"https://gitlab.com/users/sign_in/","sign in",[64,108,206,211,316,376],{"text":65,"config":66,"cards":68,"footer":91},"プラットフォーム",{"dataNavLevelOne":67},"platform",[69,75,83],{"title":65,"description":70,"link":71},"最も包括的かつAIで強化されたDevSecOpsプラットフォーム",{"text":72,"config":73},"プラットフォームを詳しく見る",{"href":74,"dataGaName":67,"dataGaLocation":47},"/ja-jp/platform/",{"title":76,"description":77,"link":78},"GitLab Duo（AI）","開発のすべてのステージでAIを活用し、ソフトウェアをより迅速にビルド",{"text":79,"config":80},"GitLab Duoのご紹介",{"href":81,"dataGaName":82,"dataGaLocation":47},"/ja-jp/gitlab-duo/","gitlab duo ai",{"title":84,"description":85,"link":86},"GitLabが選ばれる理由","GitLabが大企業に選ばれる理由10選",{"text":87,"config":88},"詳細はこちら",{"href":89,"dataGaName":90,"dataGaLocation":47},"/ja-jp/why-gitlab/","why gitlab",{"title":92,"items":93},"利用を開始：",[94,99,104],{"text":95,"config":96},"プラットフォームエンジニアリング",{"href":97,"dataGaName":98,"dataGaLocation":47},"/ja-jp/solutions/platform-engineering/","platform engineering",{"text":100,"config":101},"開発者の経験",{"href":102,"dataGaName":103,"dataGaLocation":47},"/ja-jp/developer-experience/","Developer experience",{"text":105,"config":106},"MLOps",{"href":107,"dataGaName":105,"dataGaLocation":47},"/ja-jp/topics/devops/the-role-of-ai-in-devops/",{"text":109,"left":110,"config":111,"link":113,"lists":117,"footer":188},"製品",true,{"dataNavLevelOne":112},"solutions",{"text":114,"config":115},"すべてのソリューションを表示",{"href":116,"dataGaName":112,"dataGaLocation":47},"/ja-jp/solutions/",[118,144,166],{"title":119,"description":120,"link":121,"items":126},"自動化","CI/CDと自動化でデプロイを加速",{"config":122},{"icon":123,"href":124,"dataGaName":125,"dataGaLocation":47},"AutomatedCodeAlt","/ja-jp/solutions/delivery-automation/","automated software delivery",[127,131,135,140],{"text":128,"config":129},"CI/CD",{"href":130,"dataGaLocation":47,"dataGaName":128},"/ja-jp/solutions/continuous-integration/",{"text":132,"config":133},"AIアシストによる開発",{"href":81,"dataGaLocation":47,"dataGaName":134},"AI assisted development",{"text":136,"config":137},"ソースコード管理",{"href":138,"dataGaLocation":47,"dataGaName":139},"/ja-jp/solutions/source-code-management/","Source Code Management",{"text":141,"config":142},"自動化されたソフトウェアデリバリー",{"href":124,"dataGaLocation":47,"dataGaName":143},"Automated software delivery",{"title":145,"description":146,"link":147,"items":152},"セキュリティ","セキュリティを損なうことなくコードをより迅速に完成",{"config":148},{"href":149,"dataGaName":150,"dataGaLocation":47,"icon":151},"/ja-jp/solutions/application-security-testing/","security and compliance","ShieldCheckLight",[153,157,162],{"text":154,"config":155},"Application Security Testing",{"href":149,"dataGaName":156,"dataGaLocation":47},"Application security testing",{"text":158,"config":159},"ソフトウェアサプライチェーンの安全性",{"href":160,"dataGaLocation":47,"dataGaName":161},"/ja-jp/solutions/supply-chain/","Software supply chain security",{"text":163,"config":164},"Software Compliance",{"href":165,"dataGaName":163,"dataGaLocation":47},"/ja-jp/solutions/software-compliance/",{"title":167,"link":168,"items":173},"測定",{"config":169},{"icon":170,"href":171,"dataGaName":172,"dataGaLocation":47},"DigitalTransformation","/ja-jp/solutions/visibility-measurement/","visibility and measurement",[174,178,183],{"text":175,"config":176},"可視性と測定",{"href":171,"dataGaLocation":47,"dataGaName":177},"Visibility and Measurement",{"text":179,"config":180},"バリューストリーム管理",{"href":181,"dataGaLocation":47,"dataGaName":182},"/ja-jp/solutions/value-stream-management/","Value Stream Management",{"text":184,"config":185},"分析とインサイト",{"href":186,"dataGaLocation":47,"dataGaName":187},"/ja-jp/solutions/analytics-and-insights/","Analytics and insights",{"title":189,"items":190},"GitLabが活躍する場所",[191,196,201],{"text":192,"config":193},"Enterprise",{"href":194,"dataGaLocation":47,"dataGaName":195},"/ja-jp/enterprise/","enterprise",{"text":197,"config":198},"スモールビジネス",{"href":199,"dataGaLocation":47,"dataGaName":200},"/ja-jp/small-business/","small business",{"text":202,"config":203},"公共機関",{"href":204,"dataGaLocation":47,"dataGaName":205},"/ja-jp/solutions/public-sector/","public sector",{"text":207,"config":208},"価格",{"href":209,"dataGaName":210,"dataGaLocation":47,"dataNavLevelOne":210},"/ja-jp/pricing/","pricing",{"text":212,"config":213,"link":215,"lists":219,"feature":303},"関連リソース",{"dataNavLevelOne":214},"resources",{"text":216,"config":217},"すべてのリソースを表示",{"href":218,"dataGaName":214,"dataGaLocation":47},"/ja-jp/resources/",[220,253,275],{"title":221,"items":222},"はじめに",[223,228,233,238,243,248],{"text":224,"config":225},"インストール",{"href":226,"dataGaName":227,"dataGaLocation":47},"/ja-jp/install/","install",{"text":229,"config":230},"クイックスタートガイド",{"href":231,"dataGaName":232,"dataGaLocation":47},"/ja-jp/get-started/","quick setup checklists",{"text":234,"config":235},"学ぶ",{"href":236,"dataGaLocation":47,"dataGaName":237},"https://university.gitlab.com/","learn",{"text":239,"config":240},"製品ドキュメント",{"href":241,"dataGaName":242,"dataGaLocation":47},"https://docs.gitlab.com/","product documentation",{"text":244,"config":245},"ベストプラクティスビデオ",{"href":246,"dataGaName":247,"dataGaLocation":47},"/ja-jp/getting-started-videos/","best practice videos",{"text":249,"config":250},"インテグレーション",{"href":251,"dataGaName":252,"dataGaLocation":47},"/ja-jp/integrations/","integrations",{"title":254,"items":255},"検索する",[256,261,265,270],{"text":257,"config":258},"お客様成功事例",{"href":259,"dataGaName":260,"dataGaLocation":47},"/ja-jp/customers/","customer success stories",{"text":262,"config":263},"ブログ",{"href":264,"dataGaName":5,"dataGaLocation":47},"/ja-jp/blog/",{"text":266,"config":267},"リモート",{"href":268,"dataGaName":269,"dataGaLocation":47},"https://handbook.gitlab.com/handbook/company/culture/all-remote/","remote",{"text":271,"config":272},"TeamOps",{"href":273,"dataGaName":274,"dataGaLocation":47},"/ja-jp/teamops/","teamops",{"title":276,"items":277},"つなげる",[278,283,288,293,298],{"text":279,"config":280},"GitLabサービス",{"href":281,"dataGaName":282,"dataGaLocation":47},"/ja-jp/services/","services",{"text":284,"config":285},"コミュニティ",{"href":286,"dataGaName":287,"dataGaLocation":47},"/community/","community",{"text":289,"config":290},"フォーラム",{"href":291,"dataGaName":292,"dataGaLocation":47},"https://forum.gitlab.com/","forum",{"text":294,"config":295},"イベント",{"href":296,"dataGaName":297,"dataGaLocation":47},"/events/","events",{"text":299,"config":300},"パートナー",{"href":301,"dataGaName":302,"dataGaLocation":47},"/ja-jp/partners/","partners",{"backgroundColor":304,"textColor":305,"text":306,"image":307,"link":311},"#2f2a6b","#fff","ソフトウェア開発の未来への洞察",{"altText":308,"config":309},"ソースプロモカード",{"src":310},"https://res.cloudinary.com/about-gitlab-com/image/upload/v1758208064/dzl0dbift9xdizyelkk4.svg",{"text":312,"config":313},"最新情報を読む",{"href":314,"dataGaName":315,"dataGaLocation":47},"/ja-jp/the-source/","the source",{"text":317,"config":318,"lists":320},"会社情報",{"dataNavLevelOne":319},"company",[321],{"items":322},[323,328,334,336,341,346,351,356,361,366,371],{"text":324,"config":325},"GitLabについて",{"href":326,"dataGaName":327,"dataGaLocation":47},"/ja-jp/company/","about",{"text":329,"config":330,"footerGa":333},"採用情報",{"href":331,"dataGaName":332,"dataGaLocation":47},"/jobs/","jobs",{"dataGaName":332},{"text":294,"config":335},{"href":296,"dataGaName":297,"dataGaLocation":47},{"text":337,"config":338},"経営陣",{"href":339,"dataGaName":340,"dataGaLocation":47},"/company/team/e-group/","leadership",{"text":342,"config":343},"チーム",{"href":344,"dataGaName":345,"dataGaLocation":47},"/company/team/","team",{"text":347,"config":348},"ハンドブック",{"href":349,"dataGaName":350,"dataGaLocation":47},"https://handbook.gitlab.com/","handbook",{"text":352,"config":353},"投資家向け情報",{"href":354,"dataGaName":355,"dataGaLocation":47},"https://ir.gitlab.com/","investor relations",{"text":357,"config":358},"トラストセンター",{"href":359,"dataGaName":360,"dataGaLocation":47},"/ja-jp/security/","trust center",{"text":362,"config":363},"AI Transparency Center",{"href":364,"dataGaName":365,"dataGaLocation":47},"/ja-jp/ai-transparency-center/","ai transparency center",{"text":367,"config":368},"ニュースレター",{"href":369,"dataGaName":370,"dataGaLocation":47},"/company/contact/","newsletter",{"text":372,"config":373},"プレス",{"href":374,"dataGaName":375,"dataGaLocation":47},"/press/","press",{"text":54,"config":377,"lists":378},{"dataNavLevelOne":319},[379],{"items":380},[381,384,389],{"text":54,"config":382},{"href":56,"dataGaName":383,"dataGaLocation":47},"talk to sales",{"text":385,"config":386},"サポートを受ける",{"href":387,"dataGaName":388,"dataGaLocation":47},"/support/","get help",{"text":390,"config":391},"カスタマーポータル",{"href":392,"dataGaName":393,"dataGaLocation":47},"https://customers.gitlab.com/customers/sign_in/","customer portal",{"close":395,"login":396,"suggestions":403},"閉じる",{"text":397,"link":398},"リポジトリとプロジェクトを検索するには、次にログインします",{"text":399,"config":400},"GitLab.com",{"href":61,"dataGaName":401,"dataGaLocation":402},"search login","search",{"text":404,"default":405},"提案",[406,409,414,416,420,424],{"text":76,"config":407},{"href":81,"dataGaName":408,"dataGaLocation":402},"GitLab Duo (AI)",{"text":410,"config":411},"コード提案（AI）",{"href":412,"dataGaName":413,"dataGaLocation":402},"/ja-jp/solutions/code-suggestions/","Code Suggestions (AI)",{"text":128,"config":415},{"href":130,"dataGaName":128,"dataGaLocation":402},{"text":417,"config":418},"GitLab on AWS",{"href":419,"dataGaName":417,"dataGaLocation":402},"/ja-jp/partners/technology-partners/aws/",{"text":421,"config":422},"GitLab on Google Cloud",{"href":423,"dataGaName":421,"dataGaLocation":402},"/ja-jp/partners/technology-partners/google-cloud-platform/",{"text":425,"config":426},"GitLabを選ぶ理由",{"href":89,"dataGaName":427,"dataGaLocation":402},"Why GitLab?",{"freeTrial":429,"mobileIcon":433,"desktopIcon":438},{"text":49,"config":430},{"href":431,"dataGaName":52,"dataGaLocation":432},"https://gitlab.com/-/trials/new/","nav",{"altText":434,"config":435},"GitLabアイコン",{"src":436,"dataGaName":437,"dataGaLocation":432},"https://res.cloudinary.com/about-gitlab-com/image/upload/v1758203874/jypbw1jx72aexsoohd7x.svg","gitlab icon",{"altText":434,"config":439},{"src":440,"dataGaName":437,"dataGaLocation":432},"https://res.cloudinary.com/about-gitlab-com/image/upload/v1758203875/gs4c8p8opsgvflgkswz9.svg",{"freeTrial":442,"mobileIcon":446,"desktopIcon":448},{"text":443,"config":444},"GitLab Duoの詳細について",{"href":81,"dataGaName":445,"dataGaLocation":432},"gitlab duo",{"altText":434,"config":447},{"src":436,"dataGaName":437,"dataGaLocation":432},{"altText":434,"config":449},{"src":440,"dataGaName":437,"dataGaLocation":432},"content:shared:ja-jp:main-navigation.yml","Main Navigation","shared/ja-jp/main-navigation.yml","shared/ja-jp/main-navigation",{"_path":455,"_dir":41,"_draft":6,"_partial":6,"_locale":7,"title":456,"button":457,"config":462,"_id":464,"_type":33,"_source":35,"_file":465,"_stem":466,"_extension":38},"/shared/ja-jp/banner","GitLab Duo Agent Platformがパブリックベータ版で利用可能になりました！",{"text":458,"config":459},"ベータ版を試す",{"href":460,"dataGaName":461,"dataGaLocation":47},"/ja-jp/gitlab-duo/agent-platform/","duo banner",{"layout":463},"release","content:shared:ja-jp:banner.yml","shared/ja-jp/banner.yml","shared/ja-jp/banner",{"_path":468,"_dir":41,"_draft":6,"_partial":6,"_locale":7,"data":469,"_id":673,"_type":33,"title":674,"_source":35,"_file":675,"_stem":676,"_extension":38},"/shared/ja-jp/main-footer",{"text":470,"source":471,"edit":477,"contribute":482,"config":487,"items":492,"minimal":665},"GitはSoftware Freedom Conservancyの商標です。当社は「GitLab」をライセンスに基づいて使用しています",{"text":472,"config":473},"ページのソースを表示",{"href":474,"dataGaName":475,"dataGaLocation":476},"https://gitlab.com/gitlab-com/marketing/digital-experience/about-gitlab-com/","page source","footer",{"text":478,"config":479},"このページを編集",{"href":480,"dataGaName":481,"dataGaLocation":476},"https://gitlab.com/gitlab-com/marketing/digital-experience/about-gitlab-com/-/blob/main/content/","web ide",{"text":483,"config":484},"ご協力をお願いします",{"href":485,"dataGaName":486,"dataGaLocation":476},"https://gitlab.com/gitlab-com/marketing/digital-experience/about-gitlab-com/-/blob/main/CONTRIBUTING.md/","please contribute",{"twitter":488,"facebook":489,"youtube":490,"linkedin":491},"https://twitter.com/gitlab","https://www.facebook.com/gitlab","https://www.youtube.com/channel/UCnMGQ8QHMAnVIsI3xJrihhg","https://www.linkedin.com/company/gitlab-com",[493,516,570,602,637],{"title":65,"links":494,"subMenu":499},[495],{"text":496,"config":497},"DevSecOpsプラットフォーム",{"href":74,"dataGaName":498,"dataGaLocation":476},"devsecops platform",[500],{"title":207,"links":501},[502,506,511],{"text":503,"config":504},"プランの表示",{"href":209,"dataGaName":505,"dataGaLocation":476},"view plans",{"text":507,"config":508},"Premiumを選ぶ理由",{"href":509,"dataGaName":510,"dataGaLocation":476},"/ja-jp/pricing/premium/","why premium",{"text":512,"config":513},"Ultimateを選ぶ理由",{"href":514,"dataGaName":515,"dataGaLocation":476},"/ja-jp/pricing/ultimate/","why ultimate",{"title":517,"links":518},"ソリューション",[519,524,527,529,534,539,543,546,549,554,556,558,560,565],{"text":520,"config":521},"デジタルトランスフォーメーション",{"href":522,"dataGaName":523,"dataGaLocation":476},"/ja-jp/topics/digital-transformation/","digital transformation",{"text":525,"config":526},"セキュリティとコンプライアンス",{"href":149,"dataGaName":156,"dataGaLocation":476},{"text":141,"config":528},{"href":124,"dataGaName":125,"dataGaLocation":476},{"text":530,"config":531},"アジャイル開発",{"href":532,"dataGaName":533,"dataGaLocation":476},"/ja-jp/solutions/agile-delivery/","agile delivery",{"text":535,"config":536},"クラウドトランスフォーメーション",{"href":537,"dataGaName":538,"dataGaLocation":476},"/ja-jp/topics/cloud-native/","cloud transformation",{"text":540,"config":541},"SCM",{"href":138,"dataGaName":542,"dataGaLocation":476},"source code management",{"text":128,"config":544},{"href":130,"dataGaName":545,"dataGaLocation":476},"continuous integration & delivery",{"text":179,"config":547},{"href":181,"dataGaName":548,"dataGaLocation":476},"value stream management",{"text":550,"config":551},"GitOps",{"href":552,"dataGaName":553,"dataGaLocation":476},"/ja-jp/solutions/gitops/","gitops",{"text":192,"config":555},{"href":194,"dataGaName":195,"dataGaLocation":476},{"text":197,"config":557},{"href":199,"dataGaName":200,"dataGaLocation":476},{"text":202,"config":559},{"href":204,"dataGaName":205,"dataGaLocation":476},{"text":561,"config":562},"教育",{"href":563,"dataGaName":564,"dataGaLocation":476},"/ja-jp/solutions/education/","education",{"text":566,"config":567},"金融サービス",{"href":568,"dataGaName":569,"dataGaLocation":476},"/ja-jp/solutions/finance/","financial services",{"title":212,"links":571},[572,574,576,578,581,583,586,588,590,592,594,596,598,600],{"text":224,"config":573},{"href":226,"dataGaName":227,"dataGaLocation":476},{"text":229,"config":575},{"href":231,"dataGaName":232,"dataGaLocation":476},{"text":234,"config":577},{"href":236,"dataGaName":237,"dataGaLocation":476},{"text":239,"config":579},{"href":241,"dataGaName":580,"dataGaLocation":476},"docs",{"text":262,"config":582},{"href":264,"dataGaName":5},{"text":584,"config":585},"お客様の成功事例",{"href":259,"dataGaLocation":476},{"text":257,"config":587},{"href":259,"dataGaName":260,"dataGaLocation":476},{"text":266,"config":589},{"href":268,"dataGaName":269,"dataGaLocation":476},{"text":279,"config":591},{"href":281,"dataGaName":282,"dataGaLocation":476},{"text":271,"config":593},{"href":273,"dataGaName":274,"dataGaLocation":476},{"text":284,"config":595},{"href":286,"dataGaName":287,"dataGaLocation":476},{"text":289,"config":597},{"href":291,"dataGaName":292,"dataGaLocation":476},{"text":294,"config":599},{"href":296,"dataGaName":297,"dataGaLocation":476},{"text":299,"config":601},{"href":301,"dataGaName":302,"dataGaLocation":476},{"title":603,"links":604},"Company",[605,607,609,611,613,615,617,621,626,628,630,632],{"text":324,"config":606},{"href":326,"dataGaName":319,"dataGaLocation":476},{"text":329,"config":608},{"href":331,"dataGaName":332,"dataGaLocation":476},{"text":337,"config":610},{"href":339,"dataGaName":340,"dataGaLocation":476},{"text":342,"config":612},{"href":344,"dataGaName":345,"dataGaLocation":476},{"text":347,"config":614},{"href":349,"dataGaName":350,"dataGaLocation":476},{"text":352,"config":616},{"href":354,"dataGaName":355,"dataGaLocation":476},{"text":618,"config":619},"Sustainability",{"href":620,"dataGaName":618,"dataGaLocation":476},"/sustainability/",{"text":622,"config":623},"ダイバーシティ、インクルージョン、ビロンギング（DIB）",{"href":624,"dataGaName":625,"dataGaLocation":476},"/ja-jp/diversity-inclusion-belonging/","Diversity, inclusion and belonging",{"text":357,"config":627},{"href":359,"dataGaName":360,"dataGaLocation":476},{"text":367,"config":629},{"href":369,"dataGaName":370,"dataGaLocation":476},{"text":372,"config":631},{"href":374,"dataGaName":375,"dataGaLocation":476},{"text":633,"config":634},"現代奴隷制の透明性に関する声明",{"href":635,"dataGaName":636,"dataGaLocation":476},"https://handbook.gitlab.com/handbook/legal/modern-slavery-act-transparency-statement/","modern slavery transparency statement",{"title":54,"links":638},[639,641,643,645,650,655,660],{"text":54,"config":640},{"href":56,"dataGaName":57,"dataGaLocation":476},{"text":385,"config":642},{"href":387,"dataGaName":388,"dataGaLocation":476},{"text":390,"config":644},{"href":392,"dataGaName":393,"dataGaLocation":476},{"text":646,"config":647},"ステータス",{"href":648,"dataGaName":649,"dataGaLocation":476},"https://status.gitlab.com/","status",{"text":651,"config":652},"利用規約",{"href":653,"dataGaName":654,"dataGaLocation":476},"/terms/","terms of use",{"text":656,"config":657},"プライバシーに関する声明",{"href":658,"dataGaName":659,"dataGaLocation":476},"/ja-jp/privacy/","privacy statement",{"text":661,"config":662},"Cookieの設定",{"dataGaName":663,"dataGaLocation":476,"id":664,"isOneTrustButton":110},"cookie preferences","ot-sdk-btn",{"items":666},[667,669,671],{"text":651,"config":668},{"href":653,"dataGaName":654,"dataGaLocation":476},{"text":656,"config":670},{"href":658,"dataGaName":659,"dataGaLocation":476},{"text":661,"config":672},{"dataGaName":663,"dataGaLocation":476,"id":664,"isOneTrustButton":110},"content:shared:ja-jp:main-footer.yml","Main Footer","shared/ja-jp/main-footer.yml","shared/ja-jp/main-footer",{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"seo":678,"content":679,"config":682,"_id":32,"_type":33,"title":34,"_source":35,"_file":36,"_stem":37,"_extension":38},{"title":9,"description":10,"ogTitle":9,"ogDescription":10,"noIndex":6,"ogImage":11,"ogUrl":12,"ogSiteName":13,"ogType":14,"canonicalUrls":12,"schema":15},{"title":9,"description":10,"authors":680,"heroImage":11,"date":19,"body":20,"category":21,"tags":681,"updatedDate":28},[18],[23,24,25,26,27],{"slug":30,"featured":6,"template":31},[684],{"_path":685,"_dir":686,"_draft":6,"_partial":6,"_locale":7,"content":687,"config":691,"_id":693,"_type":33,"title":18,"_source":35,"_file":694,"_stem":695,"_extension":38},"/en-us/blog/authors/michael-friedrich","authors",{"name":18,"config":688},{"headshot":689,"ctfId":690},"https://res.cloudinary.com/about-gitlab-com/image/upload/v1749659879/Blog/Author%20Headshots/dnsmichi-headshot.jpg","dnsmichi",{"template":692},"BlogAuthor","content:en-us:blog:authors:michael-friedrich.yml","en-us/blog/authors/michael-friedrich.yml","en-us/blog/authors/michael-friedrich",{"_path":697,"_dir":41,"_draft":6,"_partial":6,"_locale":7,"header":698,"eyebrow":699,"blurb":700,"button":701,"secondaryButton":705,"_id":707,"_type":33,"title":708,"_source":35,"_file":709,"_stem":710,"_extension":38},"/shared/ja-jp/next-steps","より優れたソフトウェアをより速く提供","フォーチュン100企業の50%以上がGitLabを信頼","インテリジェントなDevSecOpsプラットフォームで\n\n\nチームの可能性を広げましょう。\n",{"text":49,"config":702},{"href":703,"dataGaName":52,"dataGaLocation":704},"https://gitlab.com/-/trial_registrations/new?glm_content=default-saas-trial&glm_source=about.gitlab.com/","feature",{"text":54,"config":706},{"href":56,"dataGaName":57,"dataGaLocation":704},"content:shared:ja-jp:next-steps.yml","Next Steps","shared/ja-jp/next-steps.yml","shared/ja-jp/next-steps",1760988340952]