Skip to Content
Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理
book

Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理

by Maxwell Flitton, Caroline Morton, 中田 秀基
July 2025
Intermediate to advanced
284 pages
4h 4m
Japanese
O'Reilly Japan, Inc.
Content preview from Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理

2章非同期Rustの基本

本章ではRustで非同期を用いる際に重要な構成要素を紹介し、タスク、フューチャ、async、awaitについて概観する。さらに、コンテクスト、ピン留め、ポーリング、クロージャについても説明する。これらはRustの非同期プログラミングを十分に活用するために重要な概念だ。本章に示す例は学習のポイントを示すように選択している。したがって効率の点で最良なものであるとは限らない。本章の末尾には、これらの概念をすべて用いた例として、機密性の高いデータを扱うプログラムに対する非同期の監視ロガーを示す。

本章を読めば、タスクとフューチャを定義できるようになる。また、フューチャの技術的な構成要素であるコンテクストとピン留めについての理解が得られる。

2.1 タスクの理解

非同期プログラミングにおいては、非同期操作はタスク(task)として表現される。タスクベースの非同期パターン(TAP:task-based asynchronous pattern)は、非同期コードを抽象化したものだ。一般に、コードは一連の文(statement)の並びとして書かれる。これを、1つの文の実行が終わってから、次の文の実行が始まるように読むことができる。例えば、コーヒーとトーストを用意することを考えてみよう。これには以下のステップが必要になる。

  1. パンをトースターに入れる
  2. トーストされたパンにバターを塗る
  3. ヤカンで湯を沸かす
  4. ミルクを注ぐ
  5. インスタントコーヒーを加える(最良ではないが例を単純化するため)
  6. 湯を注ぐ

非同期プログラミングを用いれば、この手続きのスピードを確実に向上できるが、まずはこれらのステップを2つの大きなステップ、「コーヒーを淹れる」と「トーストを作る」に分けよう。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Async Rust

Async Rust

Maxwell Flitton, Caroline Morton
Rust Web Programming

Rust Web Programming

Maxwell Flitton

Publisher Resources

ISBN: 9784814401185Publisher Website