Dataset Preview
Duplicate
The full dataset viewer is not available (click to read why). Only showing a preview of the rows.
The dataset generation failed
Error code:   DatasetGenerationError
Exception:    CastError
Message:      Couldn't cast
fetched_at: timestamp[s]
books: struct<nomicon: struct<title: string, repo: string, sha: string, base_url: string, license: string,  (... 1138 chars omitted)
  child 0, nomicon: struct<title: string, repo: string, sha: string, base_url: string, license: string, excluded_parts:  (... 133 chars omitted)
      child 0, title: string
      child 1, repo: string
      child 2, sha: string
      child 3, base_url: string
      child 4, license: string
      child 5, excluded_parts: list<item: null>
          child 0, item: null
      child 6, page_count: int64
      child 7, pages: list<item: struct<book: string, path: string, title: string, part: string, url: string>>
          child 0, item: struct<book: string, path: string, title: string, part: string, url: string>
              child 0, book: string
              child 1, path: string
              child 2, title: string
              child 3, part: string
              child 4, url: string
  child 1, async-book: struct<title: string, repo: string, sha: string, base_url: string, license: string, excluded_parts:  (... 135 chars omitted)
      child 0, title: string
      child 1, repo: string
      child 2, sha: string
      child 3, base_url: string
      child 4, license: string
      child 5, excluded_parts: list<item: string>
          child 0, item: string
      child 6, page_count: int64
      child 7, pages: list<item: struct<book: string, path: string, title: string, part: string, url: string>>
          child 0, item: 
...
tle: string, part: string, url: string>
              child 0, book: string
              child 1, path: string
              child 2, title: string
              child 3, part: string
              child 4, url: string
  child 4, rust-by-example: struct<title: string, repo: string, sha: string, base_url: string, license: string, excluded_parts:  (... 133 chars omitted)
      child 0, title: string
      child 1, repo: string
      child 2, sha: string
      child 3, base_url: string
      child 4, license: string
      child 5, excluded_parts: list<item: null>
          child 0, item: null
      child 6, page_count: int64
      child 7, pages: list<item: struct<book: string, path: string, title: string, part: string, url: string>>
          child 0, item: struct<book: string, path: string, title: string, part: string, url: string>
              child 0, book: string
              child 1, path: string
              child 2, title: string
              child 3, part: string
              child 4, url: string
text: string
metadata: struct<book: string, book_title: string, part: string, chapter: string, heading_path: list<item: str (... 79 chars omitted)
  child 0, book: string
  child 1, book_title: string
  child 2, part: string
  child 3, chapter: string
  child 4, heading_path: list<item: string>
      child 0, item: string
  child 5, path: string
  child 6, url: string
  child 7, has_code: bool
  child 8, code_tags: list<item: string>
      child 0, item: string
id: string
to
{'id': Value('string'), 'text': Value('string'), 'metadata': {'book': Value('string'), 'book_title': Value('string'), 'part': Value('string'), 'chapter': Value('string'), 'heading_path': List(Value('string')), 'path': Value('string'), 'url': Value('string'), 'has_code': Value('bool'), 'code_tags': List(Value('string'))}}
because column names don't match
Traceback:    Traceback (most recent call last):
                File "/usr/local/lib/python3.14/site-packages/datasets/builder.py", line 1827, in _prepare_split_single
                  for key, table in generator:
                                    ^^^^^^^^^
                File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 613, in wrapped
                  for item in generator(*args, **kwargs):
                              ~~~~~~~~~^^^^^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/packaged_modules/json/json.py", line 343, in _generate_tables
                  self._cast_table(pa_table, json_field_paths=json_field_paths),
                  ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/packaged_modules/json/json.py", line 132, in _cast_table
                  pa_table = table_cast(pa_table, self.info.features.arrow_schema)
                File "/usr/local/lib/python3.14/site-packages/datasets/table.py", line 2378, in table_cast
                  return cast_table_to_schema(table, schema)
                File "/usr/local/lib/python3.14/site-packages/datasets/table.py", line 2306, in cast_table_to_schema
                  raise CastError(
                  ...<3 lines>...
                  )
              datasets.table.CastError: Couldn't cast
              fetched_at: timestamp[s]
              books: struct<nomicon: struct<title: string, repo: string, sha: string, base_url: string, license: string,  (... 1138 chars omitted)
                child 0, nomicon: struct<title: string, repo: string, sha: string, base_url: string, license: string, excluded_parts:  (... 133 chars omitted)
                    child 0, title: string
                    child 1, repo: string
                    child 2, sha: string
                    child 3, base_url: string
                    child 4, license: string
                    child 5, excluded_parts: list<item: null>
                        child 0, item: null
                    child 6, page_count: int64
                    child 7, pages: list<item: struct<book: string, path: string, title: string, part: string, url: string>>
                        child 0, item: struct<book: string, path: string, title: string, part: string, url: string>
                            child 0, book: string
                            child 1, path: string
                            child 2, title: string
                            child 3, part: string
                            child 4, url: string
                child 1, async-book: struct<title: string, repo: string, sha: string, base_url: string, license: string, excluded_parts:  (... 135 chars omitted)
                    child 0, title: string
                    child 1, repo: string
                    child 2, sha: string
                    child 3, base_url: string
                    child 4, license: string
                    child 5, excluded_parts: list<item: string>
                        child 0, item: string
                    child 6, page_count: int64
                    child 7, pages: list<item: struct<book: string, path: string, title: string, part: string, url: string>>
                        child 0, item: 
              ...
              tle: string, part: string, url: string>
                            child 0, book: string
                            child 1, path: string
                            child 2, title: string
                            child 3, part: string
                            child 4, url: string
                child 4, rust-by-example: struct<title: string, repo: string, sha: string, base_url: string, license: string, excluded_parts:  (... 133 chars omitted)
                    child 0, title: string
                    child 1, repo: string
                    child 2, sha: string
                    child 3, base_url: string
                    child 4, license: string
                    child 5, excluded_parts: list<item: null>
                        child 0, item: null
                    child 6, page_count: int64
                    child 7, pages: list<item: struct<book: string, path: string, title: string, part: string, url: string>>
                        child 0, item: struct<book: string, path: string, title: string, part: string, url: string>
                            child 0, book: string
                            child 1, path: string
                            child 2, title: string
                            child 3, part: string
                            child 4, url: string
              text: string
              metadata: struct<book: string, book_title: string, part: string, chapter: string, heading_path: list<item: str (... 79 chars omitted)
                child 0, book: string
                child 1, book_title: string
                child 2, part: string
                child 3, chapter: string
                child 4, heading_path: list<item: string>
                    child 0, item: string
                child 5, path: string
                child 6, url: string
                child 7, has_code: bool
                child 8, code_tags: list<item: string>
                    child 0, item: string
              id: string
              to
              {'id': Value('string'), 'text': Value('string'), 'metadata': {'book': Value('string'), 'book_title': Value('string'), 'part': Value('string'), 'chapter': Value('string'), 'heading_path': List(Value('string')), 'path': Value('string'), 'url': Value('string'), 'has_code': Value('bool'), 'code_tags': List(Value('string'))}}
              because column names don't match
              
              The above exception was the direct cause of the following exception:
              
              Traceback (most recent call last):
                File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 1369, in compute_config_parquet_and_info_response
                  parquet_operations, partial, estimated_dataset_info = stream_convert_to_parquet(
                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~^
                      builder, max_dataset_size_bytes=max_dataset_size_bytes
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                  )
                  ^
                File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 948, in stream_convert_to_parquet
                  builder._prepare_split(split_generator=splits_generators[split], file_format="parquet")
                  ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/builder.py", line 1694, in _prepare_split
                  for job_id, done, content in self._prepare_split_single(
                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~^
                      gen_kwargs=gen_kwargs, job_id=job_id, **_prepare_split_args
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                  ):
                  ^
                File "/usr/local/lib/python3.14/site-packages/datasets/builder.py", line 1880, in _prepare_split_single
                  raise DatasetGenerationError("An error occurred while generating the dataset") from e
              datasets.exceptions.DatasetGenerationError: An error occurred while generating the dataset

Need help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.

id
string
text
string
metadata
dict
async-book/intro.md#section-0
Asynchronous Programming in Rust NOTE: this guide is currently undergoing a rewrite after a long time without much work. It is work in progress, much is missing, and what exists is a bit rough.
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Introduction", "heading_path": [], "path": "intro.md", "url": "https://rust-lang.github.io/async-book/intro.html", "has_code": false, "code_tags": [] }
async-book/intro.md#introduction-1
Asynchronous Programming in Rust › Introduction This book is a guide to asynchronous programming in Rust. It is designed to help you take your first steps and to discover more about advanced topics. We don't assume any experience with asynchronous programming (in Rust or another language), but we do assume you're fami...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Introduction", "heading_path": [ "Introduction" ], "path": "intro.md", "url": "https://rust-lang.github.io/async-book/intro.html#introduction", "has_code": false, "code_tags": [] }
async-book/intro.md#what-is-async-programming-and-why-would-you-do-it-2
Asynchronous Programming in Rust › Introduction › What is Async Programming and why would you do it? In concurrent programming, the program does multiple things at the same time (or at least appears to). Programming with threads is one form of concurrent programming. Code within a thread is written in sequential style...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Introduction", "heading_path": [ "Introduction", "What is Async Programming and why would you do it?" ], "path": "intro.md", "url": "https://rust-lang.github.io/async-book/intro.htm...
async-book/intro.md#hello-world-3
Asynchronous Programming in Rust › Introduction › Hello, world! Just to give you a taste of what async Rust looks like, here is a 'hello, world' example. There is no concurrency, and it doesn't really take advantage of being async. It does define and use an async function, and it does print "hello, world!": ```rust,ed...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Introduction", "heading_path": [ "Introduction", "Hello, world!" ], "path": "intro.md", "url": "https://rust-lang.github.io/async-book/intro.html#hello-world", "has_code": true, ...
async-book/intro.md#development-of-async-rust-4
Asynchronous Programming in Rust › Introduction › Development of Async Rust The async features of Rust have been in development for a while, but it is not a 'finished' part of the language. Async Rust (at least the parts available in the stable compiler and standard libraries) is reliable and performant. It is used in...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Introduction", "heading_path": [ "Introduction", "Development of Async Rust" ], "path": "intro.md", "url": "https://rust-lang.github.io/async-book/intro.html#development-of-async-ru...
async-book/navigation/intro.md#navigation-0
Asynchronous Programming in Rust › Navigation TODO Intro to navigation - By topic - FAQs - Index
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Navigation", "heading_path": [ "Navigation" ], "path": "navigation/intro.md", "url": "https://rust-lang.github.io/async-book/navigation/intro.html#navigation", "has_code": false, "c...
async-book/navigation/topics.md#concurrency-and-parallelism-0
Asynchronous Programming in Rust › Topic index › Concurrency and parallelism - Introduction - Running async tasks in parallel using `spawn` - Running futures concurrently using `join` and `select` - Mixing sync and async concurrency
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "By topic", "heading_path": [ "Topic index", "Concurrency and parallelism" ], "path": "navigation/topics.md", "url": "https://rust-lang.github.io/async-book/navigation/topics.html#co...
async-book/navigation/topics.md#correctness-and-safety-1
Asynchronous Programming in Rust › Topic index › Correctness and safety - Cancellation - Introduction - In `select` and `try_join`
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "By topic", "heading_path": [ "Topic index", "Correctness and safety" ], "path": "navigation/topics.md", "url": "https://rust-lang.github.io/async-book/navigation/topics.html#correct...
async-book/navigation/topics.md#performance-2
Asynchronous Programming in Rust › Topic index › Performance - Blocking - Introduction - Blocking and non-blocking IO - CPU-intensive code
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "By topic", "heading_path": [ "Topic index", "Performance" ], "path": "navigation/topics.md", "url": "https://rust-lang.github.io/async-book/navigation/topics.html#performance", "h...
async-book/navigation/topics.md#testing-3
Asynchronous Programming in Rust › Topic index › Testing - Unit test syntax
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "By topic", "heading_path": [ "Topic index", "Testing" ], "path": "navigation/topics.md", "url": "https://rust-lang.github.io/async-book/navigation/topics.html#testing", "has_code"...
async-book/navigation/index.md#index-0
Asynchronous Programming in Rust › Index - Async/`async` - blocks - closures - functions - traits - c.f., threads - `await` - Blocking - IO - CPU-intensive tasks - Cancellation - `CancellationToken` - In `select` - Concurrency - c.f., parallelism - Primitives (`join`, `select`, etc.) - Cooperativ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Index", "heading_path": [ "Index" ], "path": "navigation/index.md", "url": "https://rust-lang.github.io/async-book/navigation/index.html#index", "has_code": false, "code_tags": [] }
async-book/navigation/index.md#index-1
Asynchronous Programming in Rust › Index - `join` - Joining tasks - `JoinHandle` - `abort` - Multiple runtimes - Multitasking - Cooperative, yielding - Pre-emptive - Parallelism - c.f., concurrency - Pinning, `Pin` - `race` - Reactor - Runtimes - Scheduler - `select` - Spawning tasks
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Index", "heading_path": [ "Index" ], "path": "navigation/index.md", "url": "https://rust-lang.github.io/async-book/navigation/index.html#index", "has_code": false, "code_tags": [] }
async-book/navigation/index.md#index-2
Asynchronous Programming in Rust › Index - Tasks - Spawning - Testing - Unit tests - Threads - Tokio - Traits - async - `Future` - `try_join` - `Unpin` - Waiting - Yielding - `yield_now`
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Table of Contents", "chapter": "Index", "heading_path": [ "Index" ], "path": "navigation/index.md", "url": "https://rust-lang.github.io/async-book/navigation/index.html#index", "has_code": false, "code_tags": [] }
async-book/part-guide/intro.md#part-1-a-guide-to-asynchronous-programming-in-rust-0
Asynchronous Programming in Rust › Part 1: A guide to asynchronous programming in Rust This part of the book is a tutorial-style guide to async Rust. It is aimed at newcomers to async programming in Rust. It should be useful whether or not you've done async programming in other languages. If you have, you might skip t...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Introduction", "heading_path": [ "Part 1: A guide to asynchronous programming in Rust" ], "path": "part-guide/intro.md", "url": "https://rust-lang.github.io/async-book/part-guide/intro.html...
async-book/part-guide/intro.md#core-concepts-1
Asynchronous Programming in Rust › Part 1: A guide to asynchronous programming in Rust › Core concepts We'll start by discussing different models of concurrent programming, using processes, threads, or async tasks. The first chapter will cover the essential parts of Rust's async model before we get into the nitty-grit...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Introduction", "heading_path": [ "Part 1: A guide to asynchronous programming in Rust", "Core concepts" ], "path": "part-guide/intro.md", "url": "https://rust-lang.github.io/async-book/...
async-book/part-guide/concurrency.md#concurrent-programming-0
Asynchronous Programming in Rust › Concurrent programming The goal of this chapter is to give you a high-level idea of how async concurrency works and how it is different from concurrency with threads. I think it is important to have a good mental model of what is going on before getting in to the practicalities, but ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guide/concurrency.html#concur...
async-book/part-guide/concurrency.md#concurrent-programming-1
Asynchronous Programming in Rust › Concurrent programming To give a lower-level example, a music program might need to keep playing music while the user interacts with the user interface (UI). To 'keep playing music', it might need to stream music data from the server, process that data from one format to another, and...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guide/concurrency.html#concur...
async-book/part-guide/concurrency.md#sequential-execution-2
Asynchronous Programming in Rust › Concurrent programming › Sequential execution The default mode of execution in most programming languages (including Rust) is sequential execution. ``` do_a_thing(); println!("hello!"); do_another_thing(); ``` Each statement is completed before the next one starts[^obs1]. Nothing hap...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Sequential execution" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-g...
async-book/part-guide/concurrency.md#sequential-execution-3
Asynchronous Programming in Rust › Concurrent programming › Sequential execution [^obs1]: This isn't really true: modern compilers and CPUs will reorganize your code and run it any order they like. Sequential statements are likely to overlap in many different ways. However, this should never be *observable* to the pro...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Sequential execution" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-g...
async-book/part-guide/concurrency.md#processes-and-threads-4
Asynchronous Programming in Rust › Concurrent programming › Processes and threads Processes and threads are concepts which are provided by the operating system to provide concurrency. There is one process per executable, so supporting multiple processes means a computer can run multiple programs[^proc-program] concurr...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Processes and threads" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-...
async-book/part-guide/concurrency.md#processes-and-threads-5
Asynchronous Programming in Rust › Concurrent programming › Processes and threads The OS is responsible for *scheduling* threads, which means it decides when threads run and for how long. Most modern computers have multiple cores, so they can run multiple threads at literally the same time. However, it is common to ha...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Processes and threads" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-...
async-book/part-guide/concurrency.md#processes-and-threads-6
Asynchronous Programming in Rust › Concurrent programming › Processes and threads A thread can also choose to pause itself by calling a `sleep` function, usually with a timeout. In this case the OS pauses the thread at the threads own request. Similar to pausing due to pre-emption or IO, the OS will wake the thread up...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Processes and threads" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-...
async-book/part-guide/concurrency.md#async-programming-7
Asynchronous Programming in Rust › Concurrent programming › Async programming Async programming is a kind of concurrency with the same high-level goals as concurrency with threads (do many things at the same time), but a different implementation. The two big differences between async concurrency and concurrency with t...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Async programming" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guid...
async-book/part-guide/concurrency.md#async-programming-8
Asynchronous Programming in Rust › Concurrent programming › Async programming Async concurrency is much more efficient than concurrency with threads. The memory overheads are much lower and context switching is a much cheaper operation - it doesn't require handing control to the OS and back to the program and there is...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Async programming" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guid...
async-book/part-guide/concurrency.md#async-programming-9
Asynchronous Programming in Rust › Concurrent programming › Async programming From the perspective of the whole system, blocking IO in a concurrent system with threads and non-blocking IO in an async concurrent system are similar. In both cases, IO takes time and other work gets done while the IO is happening: - With ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Async programming" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guid...
async-book/part-guide/concurrency.md#async-programming-10
Asynchronous Programming in Rust › Concurrent programming › Async programming [^threads]: We'll start our explanation assuming a program only has a single thread, but expand on that later. There will probably be other processes running on the system, but they don't really affect how async concurrency works. [^other]: ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Async programming" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guid...
async-book/part-guide/concurrency.md#concurrency-and-parallelism-11
Asynchronous Programming in Rust › Concurrent programming › Concurrency and Parallelism So far we've been talking about concurrency (doing, or appearing to do, many things at the same time), and we've hinted at parallelism (the presence of multiple CPU cores which facilitates literally doing many things at the same ti...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Concurrency and Parallelism" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book...
async-book/part-guide/concurrency.md#concurrency-and-parallelism-12
Asynchronous Programming in Rust › Concurrent programming › Concurrency and Parallelism ``` subTask1-1() subTask2-1() subTask1-2() subTask2-2() ... subTask1-100() subTask2-100() ``` Unless one task can observe the results or side-effects of a different task, then from the task's perspective, the sub-tasks are still b...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Concurrency and Parallelism" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book...
async-book/part-guide/concurrency.md#concurrency-and-parallelism-13
Asynchronous Programming in Rust › Concurrent programming › Concurrency and Parallelism In real code, things are a bit more complicated. Some sub-tasks (e.g., IO) don't require a processor to actively participate, they just need starting and some time later collecting the results. And some sub-tasks might require the ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Concurrency and Parallelism" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book...
async-book/part-guide/concurrency.md#enough-silly-examples-lets-try-to-define-things-properly-14
Asynchronous Programming in Rust › Concurrent programming › Concurrency and Parallelism › Enough silly examples, let's try to define things properly Concurrency is about ordering of computations and parallelism is about the mode of execution. Given two computations, we say they are sequential (i.e., not concurrent) if...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Concurrency and Parallelism", "Enough silly examples, let's try to define things properly" ], "path": "part-guide...
async-book/part-guide/concurrency.md#enough-silly-examples-lets-try-to-define-things-properly-15
Asynchronous Programming in Rust › Concurrent programming › Concurrency and Parallelism › Enough silly examples, let's try to define things properly Both threaded and async systems can offer both concurrency and parallelism. In both cases, concurrency is controlled by code (spawning threads or tasks) and parallelism i...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Concurrency and Parallelism", "Enough silly examples, let's try to define things properly" ], "path": "part-guide...
async-book/part-guide/concurrency.md#enough-silly-examples-lets-try-to-define-things-properly-16
Asynchronous Programming in Rust › Concurrent programming › Concurrency and Parallelism › Enough silly examples, let's try to define things properly [^p-not-c]: Can computation be parallel but not concurrent? Sort of but not really. Imagine two tasks (a and b) which consist of one sub-task each (1 and 2 belonging to a...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Concurrency and Parallelism", "Enough silly examples, let's try to define things properly" ], "path": "part-guide...
async-book/part-guide/concurrency.md#summary-17
Asynchronous Programming in Rust › Concurrent programming › Summary - There are many models of execution. We described sequential execution, threads and processes, and asynchronous programming. - Threads are an abstraction provided (and scheduled) by the OS. They usually involve pre-emptive multitasking, are paralle...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Concurrent programming", "heading_path": [ "Concurrent programming", "Summary" ], "path": "part-guide/concurrency.md", "url": "https://rust-lang.github.io/async-book/part-guide/concurre...
async-book/part-guide/async-await.md#async-and-await-0
Asynchronous Programming in Rust › Async and Await In this chapter we'll get started doing some async programming in Rust and we'll introduce the `async` and `await` keywords. `async` is an annotation on functions (and other items, such as traits, which we'll get to later); `await` is an operator used in expressions. ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.html#async-and-await", ...
async-book/part-guide/async-await.md#the-runtime-1
Asynchronous Programming in Rust › Async and Await › Rust async concepts › The runtime Async tasks must be managed and scheduled. There are typically more tasks than cores available so they can't all be run at once. When one stops executing another must be picked to execute. If a task is waiting on IO or some other ev...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Rust async concepts", "The runtime" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/pa...
async-book/part-guide/async-await.md#the-runtime-2
Asynchronous Programming in Rust › Async and Await › Rust async concepts › The runtime As well as the executor as described above, a runtime crate typically includes many utility traits and functions. These might include traits (e.g., `AsyncRead`) and implementations for IO, functionality for common IO tasks such as n...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Rust async concepts", "The runtime" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/pa...
async-book/part-guide/async-await.md#the-runtime-3
Asynchronous Programming in Rust › Async and Await › Rust async concepts › The runtime The `#[tokio::main]` annotation initializes the Tokio runtime and starts an async task for running the code in `main`. Later in this guide we'll explain in more detail what that annotation is doing and how to use async code without ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Rust async concepts", "The runtime" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/pa...
async-book/part-guide/async-await.md#futures-rs-and-the-ecosystem-4
Asynchronous Programming in Rust › Async and Await › Rust async concepts › Futures-rs and the ecosystem TODO context and history, what futures-rs is for - was used a lot, probably don't need it now, overlap with Tokio and other runtimes (sometimes with subtle semantic differences), why you might need it (working with ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Rust async concepts", "Futures-rs and the ecosystem" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github...
async-book/part-guide/async-await.md#futures-and-tasks-5
Asynchronous Programming in Rust › Async and Await › Rust async concepts › Futures and tasks The basic unit of async concurrency in Rust is the *future*. A future is just a regular old Rust object (a struct or enum, usually) which implements the 'Future' trait. A future represents a deferred computation. That is, a co...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Rust async concepts", "Futures and tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-b...
async-book/part-guide/async-await.md#futures-and-tasks-6
Asynchronous Programming in Rust › Async and Await › Rust async concepts › Futures and tasks An async task in Rust is just a future (usually a 'big' future made by combining many others). In other words, a task is a future which is executed. However, there are times when a future is 'executed' without being a runtime'...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Rust async concepts", "Futures and tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-b...
async-book/part-guide/async-await.md#async-functions-7
Asynchronous Programming in Rust › Async and Await › Async functions The `async` keyword is a modifier on function declarations. E.g., we can write `pub async fn send_to_server(...)`. An async function is simply a function declared using the `async` keyword, and what that means is that it is a function which can be ex...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Async functions" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.ht...
async-book/part-guide/async-await.md#await-8
Asynchronous Programming in Rust › Async and Await › `await` We stated above that a future is a computation that will be ready at some point in the future. To get the result of that computation, we use the `await` keyword. If the result is ready immediately or can be computed without waiting, then `await` simply does ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "`await`" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.html#await...
async-book/part-guide/async-await.md#await-9
Asynchronous Programming in Rust › Async and Await › `await` ```rust,norun // An async function, but it doesn't need to wait for anything. async fn add(a: u32, b: u32) -> u32 { a + b } async fn wait_to_add(a: u32, b: u32) -> u32 { sleep(1000).await; a + b } ``` If we call `add(15, 3).await` then it will return ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "`await`" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.html#await...
async-book/part-guide/async-await.md#await-10
Asynchronous Programming in Rust › Async and Await › `await` This is an important point about async programming in Rust. After a while it will be second nature, but it often trips up beginners, especially those who have experience with async programming in other languages. An important intuition about futures in Rust ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "`await`" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.html#await...
async-book/part-guide/async-await.md#await-11
Asynchronous Programming in Rust › Async and Await › `await` Finally, for one more perspective on `await`: we mentioned earlier that futures can be combined together to make 'bigger' futures. `async` functions are one way to define a future, and `await` is one way to combine futures. Using `await` on a future combines...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "`await`" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.html#await...
async-book/part-guide/async-await.md#some-asyncawait-examples-12
Asynchronous Programming in Rust › Async and Await › Some async/await examples Let's start by revisiting our 'hello, world!' example: ```rust,edition2021 // Define an async function. async fn say_hello() { println!("hello, world!"); } #[tokio::main] // Boilerplate which lets us write `async fn main`, we'll explai...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Some async/await examples" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/asyn...
async-book/part-guide/async-await.md#some-asyncawait-examples-13
Asynchronous Programming in Rust › Async and Await › Some async/await examples The code is a bit more interesting, but we're essentially doing the same thing - calling async functions and then awaiting to execute the result. This time we're using `?` for error handling - it works just like in synchronous Rust. For all...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Some async/await examples" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/asyn...
async-book/part-guide/async-await.md#some-asyncawait-examples-14
Asynchronous Programming in Rust › Async and Await › Some async/await examples [^async-sleep]: Note that we're using an async sleep function here, if we were to use `sleep` from std we'd put the whole thread to sleep. That wouldn't make any difference in this toy example but in a real program it would mean other tasks...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Some async/await examples" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/asyn...
async-book/part-guide/async-await.md#spawning-tasks-15
Asynchronous Programming in Rust › Async and Await › Spawning tasks We've talked about async and await as a way to run code in an async task. And we've said that `await` can put the current task to sleep while it waits for IO or some other event. When that happens, another task can run, but how do those other tasks co...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Spawning tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.htm...
async-book/part-guide/async-await.md#spawning-tasks-16
Asynchronous Programming in Rust › Async and Await › Spawning tasks Let's dive into what is happening here. There are three concepts in play: futures, tasks, and threads. The `spawn` function takes a future (which remember can be made up of many smaller futures) and runs it as a new Tokio task. Tasks are the concept w...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Spawning tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.htm...
async-book/part-guide/async-await.md#spawning-tasks-17
Asynchronous Programming in Rust › Async and Await › Spawning tasks Later in the guide we'll see cases where we execute futures concurrently, but never in parallel.
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Spawning tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide/async-await.htm...
async-book/part-guide/async-await.md#joining-tasks-18
Asynchronous Programming in Rust › Async and Await › Spawning tasks › Joining tasks If we want to get the result of executing a spawned task, then the spawning task can wait for it to finish and use the result, this is called *joining* the tasks (analogous to joining threads, and the APIs for joining are similar). Whe...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Spawning tasks", "Joining tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-...
async-book/part-guide/async-await.md#joining-tasks-19
Asynchronous Programming in Rust › Async and Await › Spawning tasks › Joining tasks The two spawned tasks are still executing concurrently. If you run the program a few times you should see both orderings. However, the `await`ed join handles are a limit on the concurrency: the final exclamation mark ('!') will *always...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Spawning tasks", "Joining tasks" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-...
async-book/part-guide/async-await.md#joinhandle-20
Asynchronous Programming in Rust › Async and Await › Spawning tasks › `JoinHandle` We'll quickly look at `JoinHandle` in a little more depth. The fact that we can `await` a `JoinHandle` is a clue that a `JoinHandle` is itself a future. `spawn` is not an `async` function, it's a regular function that returns a future (...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Async and await", "heading_path": [ "Async and Await", "Spawning tasks", "`JoinHandle`" ], "path": "part-guide/async-await.md", "url": "https://rust-lang.github.io/async-book/part-g...
async-book/part-guide/more-async-await.md#unit-tests-0
Asynchronous Programming in Rust › More async/await topics › Unit tests How to unit test async code? The issue is that you can only await from inside an async context, and unit tests in Rust are not async. Luckily, most runtimes provide a convenience attribute for tests similar to the one for `async main`. Using Tokio...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Unit tests" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-guid...
async-book/part-guide/more-async-await.md#blocking-and-cancellation-1
Asynchronous Programming in Rust › More async/await topics › Blocking and cancellation Blocking and cancellation are important to keep in mind when programming with async Rust. These concepts are not localised to any particular feature or function, but are ubiquitous properties of the system which you must understand ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Blocking and cancellation" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async...
async-book/part-guide/more-async-await.md#blocking-io-2
Asynchronous Programming in Rust › More async/await topics › Blocking and cancellation › Blocking IO We say a thread (note we're talking about OS threads here, not async tasks) is blocked when it can't make any progress. That's usually because it is waiting for the OS to complete a task on its behalf (usually I/O). Im...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Blocking and cancellation", "Blocking IO" ], "path": "part-guide/more-async-await.md", "url": "https://rust-l...
async-book/part-guide/more-async-await.md#blocking-computation-3
Asynchronous Programming in Rust › More async/await topics › Blocking and cancellation › Blocking computation You can also block the thread by doing computation (this is not quite the same as blocking I/O, since the OS is not involved, but the effect is similar). If you have a long-running computation (with or without...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Blocking and cancellation", "Blocking computation" ], "path": "part-guide/more-async-await.md", "url": "https...
async-book/part-guide/more-async-await.md#cancellation-4
Asynchronous Programming in Rust › More async/await topics › Blocking and cancellation › Cancellation Cancellation means stopping a future (or task) from executing. Since in Rust (and in contrast to many other async/await systems), futures must be driven forward by an external force (like the async runtime), if a futu...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Blocking and cancellation", "Cancellation" ], "path": "part-guide/more-async-await.md", "url": "https://rust-...
async-book/part-guide/more-async-await.md#cancellation-5
Asynchronous Programming in Rust › More async/await topics › Blocking and cancellation › Cancellation ```rust,norun async fn some_function(input: Option<Input>) { let Some(input) = input else { return; // Might terminate here (`return`). }; let x = foo(input)?; // Might terminate here (...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Blocking and cancellation", "Cancellation" ], "path": "part-guide/more-async-await.md", "url": "https://rust-...
async-book/part-guide/more-async-await.md#async-blocks-6
Asynchronous Programming in Rust › More async/await topics › Async blocks A regular block (`{ ... }`) groups code together in the source and creates a scope of encapsulation for names. At runtime, the block is executed in order and evaluates to the value of its last expression (or the unit type (`()`) if there is no t...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Async blocks" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-gu...
async-book/part-guide/more-async-await.md#async-blocks-7
Asynchronous Programming in Rust › More async/await topics › Async blocks ```rust,norun loop { { if ... { // ok continue; } } async { if ... { // not ok // continue; // ok - continues with the next execution of the `loop`...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Async blocks" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-gu...
async-book/part-guide/more-async-await.md#async-blocks-8
Asynchronous Programming in Rust › More async/await topics › Async blocks A function which returns an async block is pretty similar to an async function. Writing `async fn foo() -> ... { ... }` is roughly equivalent to `fn foo() -> ... { async { ... } }`. In fact, from the caller's perspective they are equivalent, and...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Async blocks" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-gu...
async-book/part-guide/more-async-await.md#async-closures-9
Asynchronous Programming in Rust › More async/await topics › Async closures - closures - coming soon (https://github.com/rust-lang/rust/pull/132706, https://blog.rust-lang.org/inside-rust/2024/08/09/async-closures-call-for-testing.html) - async blocks in closures vs async closures
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Async closures" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-...
async-book/part-guide/more-async-await.md#lifetimes-and-borrowing-10
Asynchronous Programming in Rust › More async/await topics › Lifetimes and borrowing - Mentioned the static lifetime above - Lifetime bounds on futures (`Future + '_`, etc.) - Borrowing across await points - I don't know, I'm sure there are more lifetime issues with async functions ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Lifetimes and borrowing" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-b...
async-book/part-guide/more-async-await.md#send--static-bounds-on-futures-11
Asynchronous Programming in Rust › More async/await topics › `Send + 'static` bounds on futures - Why they're there, multi-threaded runtimes - spawn local to avoid them - What makes an async fn `Send + 'static` and how to fix bugs with it
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "`Send + 'static` bounds on futures" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github...
async-book/part-guide/more-async-await.md#async-traits-12
Asynchronous Programming in Rust › More async/await topics › Async traits - syntax - The `Send + 'static` issue and working around it - trait_variant - explicit future - return type notation (https://blog.rust-lang.org/inside-rust/2024/09/26/rtn-call-for-testing.html) - overriding - future vs async not...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Async traits" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-gu...
async-book/part-guide/more-async-await.md#recursion-13
Asynchronous Programming in Rust › More async/await topics › Recursion - Allowed (relatively new), but requires some explicit boxing - forward reference to futures, pinning - https://rust-lang.github.io/async-book/07_workarounds/04_recursion.html - https://blog.rust-lang.org/2024/03/21/Rust-1.77.0.html#support-f...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "More async/await topics", "heading_path": [ "More async/await topics", "Recursion" ], "path": "part-guide/more-async-await.md", "url": "https://rust-lang.github.io/async-book/part-guide...
async-book/part-guide/io.md#io-and-issues-with-blocking-0
Asynchronous Programming in Rust › IO and issues with blocking Efficiently handling IO (input/output) is one of the primary motivators for async programming and most async programs do lots of IO. At it's root, the issue with IO is that it takes orders of magnitude more time than computation, therefore just waiting for...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-book/part-guide/io.html#io-and-issues-...
async-book/part-guide/io.md#blocking-and-non-blocking-io-1
Asynchronous Programming in Rust › IO and issues with blocking › Blocking and non-blocking IO IO is implemented by the operating system; the work of IO takes place in separate processes and/or in dedicated hardware, in either case outside of the program's process. IO can be either synchronous or asynchronous (aka bloc...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Blocking and non-blocking IO" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-bo...
async-book/part-guide/io.md#blocking-and-non-blocking-io-2
Asynchronous Programming in Rust › IO and issues with blocking › Blocking and non-blocking IO `write_all` is an async IO method which writes data to `stream`. This might complete immediately, but more likely this will take some time to complete, so `stream.write_all(...).await` will cause the current task to be paused...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Blocking and non-blocking IO" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-bo...
async-book/part-guide/io.md#reading-and-writing-3
Asynchronous Programming in Rust › IO and issues with blocking › Reading and writing TODO - async Read and Write traits - part of the runtime - how to use - specific implementations - network vs disk - tcp, udp - file system is not really async, but io_uring (ref to that chapter) - practical examples -...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Reading and writing" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-book/part-g...
async-book/part-guide/io.md#memory-management-4
Asynchronous Programming in Rust › IO and issues with blocking › Memory management When we read data we need to put it somewhere and when we write data it needs to be kept somewhere until the write completes. In either case, how that memory is mangaged is important. TODO - Issues with buffer management and async IO - ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Memory management" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-book/part-gui...
async-book/part-guide/io.md#advanced-topics-on-io-5
Asynchronous Programming in Rust › IO and issues with blocking › Advanced topics on IO TODO - buf read/write - Read + Write, split, join - copy - simplex and duplex - cancelation - what if we have to do sync IO? Spawn a thread or use spawn_blocking (see below)
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Advanced topics on IO" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-book/part...
async-book/part-guide/io.md#the-os-view-of-io-6
Asynchronous Programming in Rust › IO and issues with blocking › The OS view of IO TODO - Different kinds of IO and mechanisms, completion IO, reference to completion IO chapter in adv section - different runtimes can faciliate this - mio for low-level interface
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "The OS view of IO" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-book/part-gui...
async-book/part-guide/io.md#other-blocking-operations-7
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations As mentioned at the start of the chapter, not blocking threads is crucial for the performance of async programs. Blocking IO of different kinds is a common way to block, but it is also possible to block by doing lots of computat...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations" ], "path": "part-guide/io.md", "url": "https://rust-lang.github.io/async-book/...
async-book/part-guide/io.md#cpu-intensive-work-8
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › CPU-intensive work Doing long-running (i.e., cpu-intensive or cpu-bound) work will prevent the scheduler from running other tasks. This *is* a kind of blocking, but it is not as bad as blocking on IO or waiting because at leas...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "CPU-intensive work" ], "path": "part-guide/io.md", "url": "https://rust-...
async-book/part-guide/io.md#cpu-intensive-work-9
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › CPU-intensive work This example uses `spawn_blocking` to perform blocking I/O by calling a synchronous filesystem function from the standard library. Note that `tokio::fs` also exists and provides asynchronous filesystem APIs;...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "CPU-intensive work" ], "path": "part-guide/io.md", "url": "https://rust-...
async-book/part-guide/io.md#cpu-intensive-work-10
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › CPU-intensive work ```rust,norun use rayon::prelude::*; #[tokio::main] async fn main() { let data = 1..=10; let (send, recv) = tokio::sync::oneshot::channel(); // Spawn a task on rayon to avoid blocking the curre...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "CPU-intensive work" ], "path": "part-guide/io.md", "url": "https://rust-...
async-book/part-guide/io.md#cpu-intensive-work-11
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › CPU-intensive work On the other hand, you do need to do a bit more thinking: you must ensure that you are running tasks on the right runtime (which can be harder than it sounds) and communication between tasks can be complicat...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "CPU-intensive work" ], "path": "part-guide/io.md", "url": "https://rust-...
async-book/part-guide/io.md#cpu-intensive-work-12
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › CPU-intensive work For any of the above solutions, you will have tasks running in different contexts (sync and async, or different async runtimes). If you need to communicate between tasks, then you need to take care that you ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "CPU-intensive work" ], "path": "part-guide/io.md", "url": "https://rust-...
async-book/part-guide/io.md#yielding-13
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › Yielding Long-running code is an issue because it doesn't give the scheduler an opportunity to schedule other tasks. Async concurrency is cooperative: the scheduler cannot pre-empt a task to run a different one. If a long-runn...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "Yielding" ], "path": "part-guide/io.md", "url": "https://rust-lang.githu...
async-book/part-guide/io.md#yielding-14
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › Yielding A good rule of thumb is that code should not run for more than 10-100 microseconds without hitting a potential yield point.
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "Yielding" ], "path": "part-guide/io.md", "url": "https://rust-lang.githu...
async-book/part-guide/io.md#references-15
Asynchronous Programming in Rust › IO and issues with blocking › Other blocking operations › References - Tokio docs on CPU-bound tasks and blocking code - Blog post: What is Blocking? - Blog post: Using Rustlang’s Async Tokio Runtime for CPU-Bound Tasks
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "IO and issues with blocking", "heading_path": [ "IO and issues with blocking", "Other blocking operations", "References" ], "path": "part-guide/io.md", "url": "https://rust-lang.git...
async-book/part-guide/concurrency-primitives.md#composing-futures-concurrently-0
Asynchronous Programming in Rust › Composing futures concurrently In this chapter we're going to cover more ways in which futures can be composed. In particular, some new ways in which futures can be executed concurrently (but not in parallel). Superficially, the new functions/macros we introduce in this chapter are p...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io/async-book/part-gu...
async-book/part-guide/concurrency-primitives.md#composing-futures-concurrently-1
Asynchronous Programming in Rust › Composing futures concurrently The fundamental difference between join and select/race is how they handle futures completing their work: a join finishes when all futures finish, a select/race finishes when one future finishes (all the others are cancelled). There are also variations ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io/async-book/part-gu...
async-book/part-guide/concurrency-primitives.md#join-2
Asynchronous Programming in Rust › Composing futures concurrently › Join Tokio's `join` macro takes a list of futures and runs them all to completion concurrently (returning all the results as a tuple). It returns when all the futures have completed. The futures are always executed on the same thread (concurrently and...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Join" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io/async-...
async-book/part-guide/concurrency-primitives.md#join-3
Asynchronous Programming in Rust › Composing futures concurrently › Join `join` does not care about the result of the futures. In particular, if a future is cancelled or returns an error, it does not affect the others - they continue to execute. If you want 'fail fast' behaviour, use `try_join`. `try_join` works simil...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Join" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io/async-...
async-book/part-guide/concurrency-primitives.md#alternatives-4
Asynchronous Programming in Rust › Composing futures concurrently › Join › Alternatives Running futures concurrently and collecting their results is a common requirement. You should probably use `spawn` and `JoinHandle`s unless you have a good reason not to (i.e., you explicitly do not want parallelism, and even then ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Join", "Alternatives" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-l...
async-book/part-guide/concurrency-primitives.md#alternatives-5
Asynchronous Programming in Rust › Composing futures concurrently › Join › Alternatives Futures-concurrency also provides functionality for join (and try_join). In the futures-concurrency style, these operations are trait methods on groups of futures such as tuples, `Vec`s, or arrays. E.g., to join two futures, you wo...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Join", "Alternatives" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-l...
async-book/part-guide/concurrency-primitives.md#raceselect-6
Asynchronous Programming in Rust › Composing futures concurrently › Race/select The counterpart to joining futures is racing them (aka selecting on them). With race/select the futures are executed concurrently, but rather than waiting for all the futures to complete, we only wait for the first one to complete and then...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/concurrency-primitives.md#raceselect-7
Asynchronous Programming in Rust › Composing futures concurrently › Race/select - pattern matching: the syntax on the left of `=` on each branch can be a pattern and the block is only executed if the result of the future matches the pattern. If the pattern does not match, then the future is no longer polled (but other...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/concurrency-primitives.md#raceselect-8
Asynchronous Programming in Rust › Composing futures concurrently › Race/select As with `join!`, `select!` does not treat `Result`s in any special way (other than the pattern matching mentioned previously) and if a branch completes with an error, then all other branches will be cancelled and the error will be used as ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/concurrency-primitives.md#raceselect-9
Asynchronous Programming in Rust › Composing futures concurrently › Race/select In this example, we read values from `stream` and print them until there are none left or waiting for a result times out. What happens to any remaining data in the stream in the timeout case depends on the implementation of the stream (it ...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/concurrency-primitives.md#raceselect-10
Asynchronous Programming in Rust › Composing futures concurrently › Race/select In the above example, when `timeout` is ready, we `break` out of the loop. But what if we didn't do that? In that case, `select` would simply poll `timeout` again, which the `Future` docs say should not happen! `select` can't help this, it...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/concurrency-primitives.md#raceselect-11
Asynchronous Programming in Rust › Composing futures concurrently › Race/select Now, lets consider the type of `&mut timeout`. Lets assume that `timeout()` returns a type which implements `Future`, which might be an anonymous type from an async function, or it might be a named type like `Timeout`. Lets assume the latt...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/concurrency-primitives.md#alternatives-1-12
Asynchronous Programming in Rust › Composing futures concurrently › Race/select › Alternatives Futures.rs has its own `select` macro and futures-concurrency has a Race trait which are alternatives to Tokio's `select` macro. These both have the same core semantics of concurrently racing multiple futures, processing the...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select", "Alternatives" ], "path": "part-guide/concurrency-primitives.md", "url": "https:/...
async-book/part-guide/concurrency-primitives.md#alternatives-1-13
Asynchronous Programming in Rust › Composing futures concurrently › Race/select › Alternatives A common use for `select` (especially inside a loop) is working with streams. There are stream combinator methods which can replace some uses of select. For example, `merge` in futures-concurrency is a good alternative to me...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Race/select", "Alternatives" ], "path": "part-guide/concurrency-primitives.md", "url": "https:/...
async-book/part-guide/concurrency-primitives.md#final-words-14
Asynchronous Programming in Rust › Composing futures concurrently › Final words In this section we've talked about two ways to run groups of futures concurrently. Joining futures means waiting for them all to finish; selecting (aka racing) futures means waiting for the first to finish. In contrast to spawning tasks, t...
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Composing futures concurrently", "heading_path": [ "Composing futures concurrently", "Final words" ], "path": "part-guide/concurrency-primitives.md", "url": "https://rust-lang.github.io...
async-book/part-guide/sync.md#channels-locking-and-synchronization-0
Asynchronous Programming in Rust › Channels, locking, and synchronization note on runtime specificness of sync primitves Why we need async primitives rather than use the sync ones
{ "book": "async-book", "book_title": "Asynchronous Programming in Rust", "part": "Part 1: guide", "chapter": "Channels, locking, and synchronization", "heading_path": [ "Channels, locking, and synchronization" ], "path": "part-guide/sync.md", "url": "https://rust-lang.github.io/async-book/part-guid...
End of preview.

No dataset card yet

Downloads last month
-