### Structured Logging Example Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_8_log/README.md Examples of structured log messages in JSON format, including fields for level, file, time, and message. Some logs include additional contextual data. ```json {"lvl":"ERROR","file":"app.log","time":"2018-07-30T12:14:14.196483657Z","msg":"Error occurred"} ``` ```json {"lvl":"INFO","file":"access.log","time":"2018-07-30T12:17:18.721127239Z","msg":"http","method":"POST","path":"/some"} ``` -------------------------------- ### PhantomData Transparency Example Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_9_phantom/README.md Demonstrates how PhantomData affects auto traits like Send and Sized. The first example shows `Nonce<()>` is Send, while `Nonce>` and `Nonce` are not, due to the substituted types. ```rust struct Nonce(PhantomData, usize); // This compiles OK, as `Nonce<()>` is `Send`. let nonce: Nonce<()> = Nonce(PhantomData, 1); thread::spawn(move || { println!("{nonce:?}"); }); // This doesn't compile, as `Nonce>` is not `Send`. let nonce: Nonce> = Nonce(PhantomData, 2); thread::spawn(move || { println!("{nonce:?}"); }); // This doesn't compile, as `dyn Any` is not `Sized`. let nonce: Nonce = Nonce(PhantomData, 3); ``` -------------------------------- ### Dynamic Dispatch Example Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_6_dispatch/README.md Demonstrates dynamic dispatch using a vector of trait objects to hold heterogeneous types that implement the `SayHello` trait. Requires `Box` to manage different concrete types at runtime. ```rust trait SayHello { fn say_hello(&self); } struct English; impl SayHello for English { fn say_hello(&self) { println!("Hello!") } } struct Spanish; impl SayHello for Spanish { fn say_hello(&self) { println!("Hola!") } } // We have to use trait object here to contain different types. let greetings: Vec> = vec![ Box::new(English), Box::new(Spanish), ]; ``` -------------------------------- ### Rust Box Ownership Example (Fails) Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_3_rc_cell/README.md Demonstrates a common ownership error in Rust where a value is moved and cannot be used again. This code will not compile. ```rust struct Val(u8); let a = Val(5); let x = Box::new(a); let y = Box::new(a); ``` -------------------------------- ### Clone Repository and Set Up Upstream Remote Source: https://github.com/rust-lang-ua/rustcamp/blob/master/faq.md If a merge with '--allow-unrelated-histories' results in too many conflicts, clone the repository again and set up the upstream remote. This process helps resolve complex merge conflicts by starting fresh. ```bash git clone https://github.com/YourUsername/your_repo.git cd your_repo git remote add upstream https://github.com/rust-lang-ua/rustcamp.git ``` -------------------------------- ### CommandHandler Implementation with Trait Object Context Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_7_sized/README.md This example shows an implementation of the CommandHandler trait for a User type, using a trait object `dyn UserRepository` for the Context. This showcases the practical application of the ?Sized bound for handling unsized types. ```rust impl CommandHandler for User { type Context = dyn UserRepository; type Result = Result<(), UserError>; fn handle_command(&self, cmd: &CreateUser, user_repo: &Self::Context) -> Self::Result { // Here we operate with the `UserRepository` // via its trait object `&dyn UserRepository` } } ``` -------------------------------- ### Rust Function-Like Procedural Macro Example Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md Defines a function-like procedural macro that generates a Rust function. It takes `TokenStream` as input and returns a `TokenStream` representing the generated code. ```rust #[proc_macro] pub fn make_answer(_: TokenStream) -> TokenStream { "fn answer() -> u32 { 42 }".parse().unwrap() } ``` -------------------------------- ### Rust Attribute Procedural Macro Example Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md Defines an attribute procedural macro that can be applied to Rust items. It receives attributes and the item itself as `TokenStream`. ```rust #[proc_macro_attribute] pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream { // code... } ``` -------------------------------- ### Fact Type Implementation Task Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_9_phantom/README.md A placeholder for implementing a `Fact` type that provides random facts about the type `T`. The example shows how to instantiate and use the `Fact` type. ```rust let f: Fact> = Fact::new(); println!("Fact about Vec: {}", f.fact()); println!("Fact about Vec: {}", f.fact()); ``` -------------------------------- ### Rust Derive Procedural Macro Example Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md Defines a derive procedural macro that enables custom implementations for `#[derive(Trait)]`. It takes the `TokenStream` of the item it's derived for. ```rust #[proc_macro_derive(AnswerFn)] pub fn derive_answer_fn(_: TokenStream) -> TokenStream { "impl Struct{ fn answer() -> u32 { 42 } }".parse().unwrap() } ``` -------------------------------- ### Avoiding Deadlocks by Separating Mutex Scopes Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_3_rc_cell/README.md This example shows how to prevent deadlocks by ensuring that the locking scopes for `Arc>` do not intersect. Each lock is acquired and released within its own distinct scope. ```rust let owner1 = Arc::new(Mutex::new("string")); let owner2 = owner1.clone(); { let value = owner1.lock.unwrap(); // No intersection as owner1 locking scope ends here. } { let value = owner2.lock.unwrap(); } ``` -------------------------------- ### Swapping enum variants with mem::replace Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_2_mem_replace/README.md This example shows how to use `mem::replace` to swap the contents of an enum variant, replacing the original value with a default (empty String) to satisfy ownership rules without extra allocations. ```rust enum MyEnum { A { name: String }, B { name: String }, } fn swizzle(e: &mut MyEnum) { use self::MyEnum::*; *e = match *e { // Ownership rules do not allow taking `name` by value, but we cannot // take the value out of a mutable reference, unless we replace it: A { ref mut name } => B { name: mem::replace(name, String::new()) }, B { ref mut name } => A { name: mem::replace(name, String::new()) }, } } ``` -------------------------------- ### Loading Configuration from Files and Environment Variables with config Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_9_cmd_env_conf/README.md Shows how to use the config crate to load hierarchical configuration from multiple sources, including files (TOML) and environment variables, with defined priorities. ```rust use config::{Config, File, Environment, Value}; use serde::Deserialize; #[derive(Deserialize, Debug)] struct AppConfig { debug: bool, database: DatabaseConfig, } #[derive(Deserialize, Debug)] struct DatabaseConfig { server: String, ports: Vec, } fn main() -> Result<(), Box> { let settings = Config::builder() .set_default("debug", false)? .set_default("database.server", "localhost".to_string())? .set_default("database.ports", vec![8080])? .add_source(File::with_name("config.toml")) .add_source(Environment::with_prefix("CONF")) .build()?; let s: AppConfig = settings.try_deserialize()?; println!("{:?}", s); Ok(()) } ``` -------------------------------- ### Async CLI Tool for Web Page Downloads Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_11_async/README.md This snippet outlines the command-line interface for an asynchronous tool that downloads web pages. It specifies how to run the tool, specify the input file containing links, and optionally control the maximum number of concurrent threads. ```bash cargo run -p task_3_11 -- [--max-threads=] ``` -------------------------------- ### Instantiating Structs with Default Values Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_1_default_clone_copy/README.md Shows how to instantiate a struct using `Default::default()` to fill in fields that are not explicitly provided, assuming the struct has a `Default` implementation. ```rust let x = Foo { bar: baz, ..Default::default() }; ``` -------------------------------- ### Usage of Function-Like Procedural Macro Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md Demonstrates how to invoke a function-like procedural macro, similar to how declarative macros are used. ```rust make_answer!(); ``` -------------------------------- ### Impl block with trait bounds on type Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_3_bound_impl/README.md An example of trait bounds pollution where a bound is repeated in an impl block, even if not needed for that specific implementation. ```rust struct UserService { repo: R, } impl Display for UserService where R: Display + UserRepo, // <- We are not interested in UserRepo here, { // all we need is just Display. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "UserService with repo {}", self.repo) } } ``` -------------------------------- ### Basic Serialization and Deserialization with Serde Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_6_serde/README.md Demonstrates how to serialize a Rust struct to a JSON string and deserialize it back using the `serde` and `serde_json` crates. Ensure `serde` and `serde_json` are added as dependencies. ```rust use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] struct Point { x: i32, y: i32, } fn main() { let point = Point { x: 1, y: 2 }; let serialized = serde_json::to_string(&point).unwrap(); println!("serialized = {}", serialized); let deserialized: Point = serde_json::from_str(&serialized).unwrap(); println!("deserialized = {:?}", deserialized); } ``` -------------------------------- ### Defining CLI with clap derive Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_9_cmd_env_conf/README.md Shows how to define command-line interface options declaratively using the clap crate with its derive feature. ```rust use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { /// Enables debug mode #[arg(short, long)] debug: bool, /// Path to configuration file #[arg(short, long, env = "CONF_FILE", default_value = "config.toml")] conf: String, } fn main() { let args = Args::parse(); println!("{:?}", args); } ``` -------------------------------- ### Buffer get_and_reset without mem::replace (fails) Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_2_mem_replace/README.md This example shows a common scenario where the borrow checker prevents moving a value out of a mutable reference, leading to an error. ```rust impl Buffer { fn get_and_reset(&mut self) -> Vec { // error: cannot move out of dereference of `&mut`-pointer let buf = self.buf; self.buf = Vec::new(); buf } } ``` -------------------------------- ### Setting Environment Variables from a .env file with dotenv Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_9_cmd_env_conf/README.md Demonstrates how to load environment variables from a .env file into the current process environment using the dotenv crate. This is particularly useful for development. ```rust fn main() { // Load .env file dotenv::dotenv().ok(); // Now you can access variables set in .env using std::env::var match std::env::var("DATABASE_URL") { Ok(url) => println!("Database URL: {}", url), Err(_) => println!("DATABASE_URL not set."), } } ``` -------------------------------- ### Deadlock Example with Intersecting Mutex Scopes Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_3_rc_cell/README.md This code demonstrates how deadlocks occur when locking scopes of two `Arc>` instances intersect. Avoid this by ensuring lock scopes do not overlap. ```rust let owner1 = Arc::new(Mutex::new("string")); let owner2 = owner1.clone(); let value = owner1.lock.unwrap(); // owner2 locking scope intersects with owner1 lock's scope. let value = owner2.lock.unwrap(); ``` -------------------------------- ### Reference-to-Reference Conversion with AsRef Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_5_convert_cast_deref/README.md Shows how to perform a cheap, non-fallible reference-to-reference conversion using the `.as_ref()` method. This is useful for converting owned types to references without consuming ownership. ```rust let string: String = "some text".into(); let bytes: &[u8] = string.as_ref(); ``` -------------------------------- ### Type Casting with 'as' Keyword Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_5_convert_cast_deref/README.md Illustrates using the 'as' keyword for type casting, specifically converting a usize to f64 for division. Note that 'as' supports a limited set of transformations. ```rust fn average(values: &[f64]) -> f64 { let sum: f64 = sum(values); let size: f64 = len(values) as f64; sum / size } ``` -------------------------------- ### Static Dispatch Optimization with Enum Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_6_dispatch/README.md Refactors the dynamic dispatch example to use static dispatch via an enum for a closed set of types. This avoids runtime overhead by matching on the enum variants. ```rust trait SayHello { fn say_hello(&self); } struct English; impl SayHello for English { fn say_hello(&self) { println!("Hello!") } } struct Spanish; impl SayHello for Spanish { fn say_hello(&self) { println!("Hola!") } } enum Language { English(English), Spanish(Spanish), } impl SayHello for Language { fn say_hello(&self) { match self { Language::English(l) => l.say_hello(), Language::Spanish(l) => l.say_hello(), } } } // We contain different types without using trait objects. let greetings: Vec = vec![English, Spanish]; ``` -------------------------------- ### Usage of Derive Procedural Macro Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md Illustrates how to use a derive macro, such as `AnswerFn`, on a struct or enum to automatically generate trait implementations. ```rust #[derive(AnswerFn)] struct Struct; ``` -------------------------------- ### Reading Environment Variables with std::env Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_9_cmd_env_conf/README.md Illustrates how to read environment variables as raw strings using the std::env module in Rust. ```rust use std::env; fn main() { match env::var("MY_VARIABLE") { Ok(val) => println!("MY_VARIABLE is set to: {}", val), Err(e) => println!("Could not read MY_VARIABLE: {}", e), } } ``` -------------------------------- ### Ergonomic API with Abstracted Input Types Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_4_generic_in_type_out/README.md Demonstrates how to use generic type parameters with traits like AsRef and AsMut to accept various input types, improving API ergonomics by hiding explicit type conversions. ```rust use derive_more::{AsRef, AsMut}; pub fn just_print_stringy>(v: S) { println!("{}", v.as_ref()) } pub fn add_hi>(mut v: S) { v.as_mut().push_str(" Hi") } #[derive(AsMut, AsRef)] pub struct Nickname(String); impl Nickname { pub fn new>(nickname: S) -> Self { Self(nickname.into()) } } ``` -------------------------------- ### Add Upstream Remote and Merge Changes Source: https://github.com/rust-lang-ua/rustcamp/blob/master/faq.md Use these commands to add the main repository as a remote and fetch/merge changes. Ensure you have the correct repository URL. ```bash git remote add upstream git@github.com:rust-lang-ua/rustcamp.git git fetch --all git merge upstream/master ``` -------------------------------- ### musli: Serialize Data in Different Modes Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_6_serde/README.md Demonstrates how to use musli to serialize the same data model into different formats (JSON and a custom packed format) by defining custom modes. ```rust use musli::mode::{DefaultMode, Mode}; use musli::{Decode, Encode}; use musli_json::Encoding; enum Alt {} impl Mode for Alt {} #[derive(Decode, Encode)] #[musli(mode = Alt, packed)] #[musli(default_field_name = "name")] struct Word<'a> { text: &'a str, teineigo: bool, } let CONFIG: Encoding = Encoding::new(); let ALT_CONFIG: Encoding = Encoding::new(); let word = Word { text: "あります", teineigo: true, }; let out = CONFIG.to_string(&word)?; assert_eq!(out, r#"{"text":"あります","teineigo":true}"#); let out = ALT_CONFIG.to_string(&word)?; assert_eq!(out, r#"["あります",true]"#); ``` -------------------------------- ### Post State Machine Diagram Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_1_type_safety/README.md This diagram illustrates the state transitions for a Post type: New, Unmoderated, Published, and Deleted. It shows allowed transitions like publish(), allow(), deny(), and delete() between states. ```text +-----+ +-------------+ +-----------+ | New |--publish()-->| Unmoderated |--allow()-->| Published | +-----+ +-------------+ +-----------+ | deny() | | +---------+ delete() +------>| Deleted |<------+ +---------+ ``` -------------------------------- ### Idiomatic API Usage with Abstracted Input Types Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_4_generic_in_type_out/README.md Shows the simplified usage of an API after abstracting over input types, eliminating the need for explicit conversion methods like .as_ref() and .as_mut(). ```rust let mut nickname = Nickname::new("Vasya"); add_hi(&mut nickname); just_print_stringy(&nickname); ``` -------------------------------- ### Custom Default Values with smart-default Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_1_default_clone_copy/README.md Demonstrates using the `smart-default` crate for more complex default value implementations, including nested structures and specific initializations. ```rust #[derive(SmartDefault)] enum Foo { Bar, #[default] Baz { #[default = 12] a: i32, b: i32, #[default(Some(Default::default()))] c: Option, #[default(_code = "vec![1, 2, 3]")] d: Vec, #[default = "four"] e: String, }, Qux(i32), } ``` -------------------------------- ### Basic Function Signatures for Input Types Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_4_generic_in_type_out/README.md Illustrates standard Rust practices for handling input parameters based on access needs: read-only reference (&T), mutable reference (&mut T), and ownership transfer (T). ```rust use derive_more::{AsRef, AsMut}; // Read-only access is enough here. pub fn just_print_stringy(v: &str) { println!("{}", v) } // We want to change `v`, but don't own. pub fn add_hi(v: &mut String) { v.push_str(" Hi") } #[derive(AsMut, AsRef)] pub struct Nickname(String); impl Nickname { // We want to own `nickname` inside `Nickname` value. pub fn new(nickname: String) -> Self { Self(nickname) } } ``` -------------------------------- ### Rust Cow vs Beef Crate Size Comparison Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_4_cow/README.md Compares the memory size of Rust's standard library Cow with the Cow from the 'beef' crate. This highlights the potential memory efficiency gains offered by the 'beef' crate's implementations. ```rust use std::mem::size_of; const WORD: usize = size_of::(); assert_eq!(size_of::>(), 4 * WORD); assert_eq!(size_of::>(), 3 * WORD); // Lean variant is two words on 64-bit architecture #[cfg(target_pointer_width = "64")] assert_eq!(size_of::>(), 2 * WORD); ``` -------------------------------- ### Value-to-Value Conversion with Into and TryInto Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_5_convert_cast_deref/README.md Demonstrates non-fallible conversion using `.into()` and fallible conversion using `.try_into()` with `expect` for error handling. These traits consume ownership of the value. ```rust let num: u32 = 5; let big_num: u64 = num.into(); let small_num: u16 = big_num.try_into().expect("Value is too big"); ``` -------------------------------- ### Define and Use a Declarative Macro with macro_rules! Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md This snippet shows how to define a declarative macro named 'vec!' using macro_rules! for creating a Vec. It also demonstrates its usage with multiple arguments. ```rust macro_rules! vec { ( $( $x:expr ),* ) => { { let mut temp_vec = Vec::new(); $( temp_vec.push($x); ) * temp_vec } }; } let v = vec![1, 2, 3]; ``` -------------------------------- ### Accessing Command-Line Arguments with std::env Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_9_cmd_env_conf/README.md Demonstrates the basic usage of the std::env::args iterator to access command-line arguments passed to a Rust program. ```rust use std::env; fn main() { let args: Vec = env::args().collect(); println!("Arguments: {:?}", args); } ``` -------------------------------- ### Struct with manual Clone implementation Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_3_bound_impl/README.md Shows how a manual `Clone` implementation can avoid unnecessary trait bounds, allowing the struct to be cloned even if its type parameters do not implement `Clone`. ```rust struct Loader { state: Arc>> } // Manual implementation is used to omit applying unnecessary Clone bounds. impl Clone for Loader { fn clone(&self) -> Self { Self { state: self.state.clone(), } } } let loader: Loader = ..; let copy = loader.clone(); // it compiles now! ``` -------------------------------- ### Reading Typed Data from Environment Variables with envy Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_9_cmd_env_conf/README.md Demonstrates using the envy crate to parse environment variables into a typed struct, leveraging serde attributes for mapping. ```rust use serde::Deserialize; #[derive(Deserialize, Debug)] struct AppConfig { database_url: String, port: u16, } fn main() -> Result<(), envy::Error> { let config: AppConfig = envy::from_env()?; println!("{:?}", config); Ok(()) } ``` -------------------------------- ### PhantomData with ?Sized Constraint Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_9_phantom/README.md Shows how to use PhantomData with a ?Sized constraint to ensure desired auto trait implementations, regardless of the substituted type. This allows `Nonce>` and `Nonce` to compile. ```rust struct Nonce(PhantomData>>, usize); // This compiles OK now, despite `Rc<()>` is not `Send`. let nonce: Nonce> = Nonce(PhantomData, 2); thread::spawn(move || { println!("{nonce:?}"); }); // This compiles OK now, as any `?Sized` type is allowed. let nonce: Nonce = Nonce(PhantomData, 3); ``` -------------------------------- ### Inner-to-Outer Reference Conversion with AsRef Source: https://github.com/rust-lang-ua/rustcamp/blob/master/1_concepts/1_5_convert_cast_deref/README.md Demonstrates implementing AsRef for inner-to-outer reference conversion. Note that direct conversion can lead to issues with temporary values. ```rust struct Id(u8); impl AsRef for Id { fn as_ref(&self) -> &u8 { &self.0 } } impl AsRef for u8 { fn as_ref(&self) -> &Id { &Id(*self) } } ``` -------------------------------- ### Buffer get_and_reset with mem::replace (success) Source: https://github.com/rust-lang-ua/rustcamp/blob/master/2_idioms/2_2_mem_replace/README.md This snippet demonstrates the correct usage of `mem::replace` to swap the buffer with a new empty vector, avoiding borrow checker errors and unnecessary clones. ```rust impl Buffer { fn get_and_reset(&mut self) -> Vec { mem::replace(&mut self.buf, Vec::new()) } } ``` -------------------------------- ### Create New Branch and Reset to Upstream Master Source: https://github.com/rust-lang-ua/rustcamp/blob/master/faq.md After cloning and setting up the upstream remote, create a new branch and reset it to the state of 'upstream/master'. This prepares the repository for easier conflict resolution. ```bash git fetch upstream master git checkout -b template git reset upstream/master ``` -------------------------------- ### Usage of Attribute Procedural Macro Source: https://github.com/rust-lang-ua/rustcamp/blob/master/3_ecosystem/3_2_macro/README.md Shows how to apply a custom attribute macro, like `route`, to a Rust function, potentially with arguments. ```rust #[route(GET, "/")] fn index() {} ``` -------------------------------- ### HTML Handler for a Simple Web Page Source: https://github.com/rust-lang-ua/rustcamp/blob/master/5_zero2prod/3_chapter/3_5.md This Rust handler function generates a basic HTML page. It's suitable for serving static content. ```rust async fn run( _: Request ) -> Result, Infallible> { Ok(Response::builder() .status(StatusCode::OK) .header(header::CONTENT_TYPE, mime::TEXT_HTML_UTF_8.as_ref()) .body(Body::from( r#" Exercise 1

Hello world!

"# )) .unwrap()) } ```