Skip to content

A small tutorial to get started with tokio and rust async/await

Notifications You must be signed in to change notification settings

tdejager/tutorial_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bot Tutorial

This is a simple tutorial for people getting up to speed with async Rust using tokio. The goal is to help a small robot get to his food. To do this you will need to use async-rust programming foo to help this robot achieve his goal The server has been made which is a TCP server, including a small debug GUI so that the world state can be visualized. Take a look at server.rs for an example.

The R in the GUI represents the robot and the F is the food.

debug-gui

Goal

The goal is to create a client that can help get the robot to it's food. The code from the shared lib.rs can be used to achieve this. The datatypes can be serialized over the wire using bincode.

Before starting

  1. Take a look at the tests/async_examples.rs which shows how the async/await code can be used in Rust. This is similar to async code in Typescript or Python. It just scratches the surface especially with regards to borrowing but you can read more about that later.
  2. Maybe read the chapter from the book on error handling: Error Handling. We are using anyhow for easy error handling.

Assignments

  1. The first goal is to familiarize yourself with the lib.rs code. To do this you need to complete a test that was written there that checks one of the constrainst from the World.
  2. The second goal is to create a client that navigate the robot to the food. To do this you need to create a TCP client to connect to the server using tokio. An example can be found: hello-world. Check the Cargo.toml file to check where the second binary is defined it can be run with cargo r --bin bot_client

Open questions

  1. There is a potential flaw in the code: for the synchronization primitives I'm using an std::sync::RwLock from the standard library. Tokio also provides the same primitives but instead the blocking methods can be .await'ed. Do you have an idea what problem this can cause and why? Look a the test/async_examples.rs to see the difference in usage.

About

A small tutorial to get started with tokio and rust async/await

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages