
Agglayer node Engineering Team leader at @0xPolygon Labs ~ Previously, Staff Rust software Engineer at @Toposware ~ Sometimes I do live coding about @rustlang
- Tweets984
- Following197
- Followers364
- Likes155

ALT Screenshot of the O'Reilly website showing a book cover of "Rust Atomics and Locks - Low-Level Concurrency in Practice". The cover has a black and white kodiak bear and a sticker showing "Early Release - raw & unedited". The text next to the cover reads as follows: Rust Atomics and Locks by Mara Bos Released November 2022 Publisher(s): O'Reilly Media, Inc. ISBN: 9781098119423 In this practical book, Mara Bos, leader of the Rust library team, helps Rust programmers of all levels gain a clear understanding of low-level concurrency. You'll learn everything about atomics and memory ordering and how they're combined with basic operating system APIs to build common primitives like mutexes and condition variables. Once you're done, you'll have a firm grasp of how Rust's memory model, the processor, and the roles of the operating system all fit together.
![// Iterators over Option<>s can be collected in different ways: let a = [Some(1), Some(2), Some(3)]; let b = [Some(1), None, Some(3)]; // 1. Just collect the Option values: let _: Vec<Option<i32>> = a.into_iter().collect(); // [Some(1), Some(2), Some(3)] let _: Vec<Option<i32>> = b.into_iter().collect(); // [Some(1), None, Some(3)] // 2. Collect and unwrap the Some()s, stopping at None: let _: Option<Vec<i32>> = a.into_iter().collect(); // Some([1, 2, 3]) let _: Option<Vec<i32>> = b.into_iter().collect(); // None](https://pbs.twimg.com/media/E-qnRPhWEAAb104.jpg?name=small&format=webp)
ALT // Iterators over Option<>s can be collected in different ways: let a = [Some(1), Some(2), Some(3)]; let b = [Some(1), None, Some(3)]; // 1. Just collect the Option values: let _: Vec<Option<i32>> = a.into_iter().collect(); // [Some(1), Some(2), Some(3)] let _: Vec<Option<i32>> = b.into_iter().collect(); // [Some(1), None, Some(3)] // 2. Collect and unwrap the Some()s, stopping at None: let _: Option<Vec<i32>> = a.into_iter().collect(); // Some([1, 2, 3]) let _: Option<Vec<i32>> = b.into_iter().collect(); // None
![// Iterators over Result<>s can be collected in different ways: let a = [Ok(1), Ok(2), Ok(3)]; let b = [Ok(1), Err("!"), Ok(3)]; // 1. Just collect the Result values: let _: Vec<Result<i32, &str>> = a.into_iter().collect(); // [Ok(1), Ok(2), Ok(3)] let _: Vec<Result<i32, &str>> = b.into_iter().collect(); // [Ok(1), Err("!"), Ok(3)] // 2. Collect Ok()s, stopping at Err(): let _: Result<Vec<i32>, &str> = a.into_iter().collect(); // Ok([1, 2, 3]) let _: Result<Vec<i32>, &str> = b.into_iter().collect(); // Err("!")](https://pbs.twimg.com/media/E-qoKgrWUAEA2_0.jpg?name=small&format=webp)
ALT // Iterators over Result<>s can be collected in different ways: let a = [Ok(1), Ok(2), Ok(3)]; let b = [Ok(1), Err("!"), Ok(3)]; // 1. Just collect the Result values: let _: Vec<Result<i32, &str>> = a.into_iter().collect(); // [Ok(1), Ok(2), Ok(3)] let _: Vec<Result<i32, &str>> = b.into_iter().collect(); // [Ok(1), Err("!"), Ok(3)] // 2. Collect Ok()s, stopping at Err(): let _: Result<Vec<i32>, &str> = a.into_iter().collect(); // Ok([1, 2, 3]) let _: Result<Vec<i32>, &str> = b.into_iter().collect(); // Err("!")
![// () items can be collected into a single (), since it carries no information: let _: () = [(), (), (), (), ()].into_iter().collect(); // This also works for Result<(), E>, collecting the Ok(()) into a single Ok(()): let _: Result<(), &str> = [Ok(()), Ok(()), Ok(())].into_iter().collect(); // Ok(()) let _: Result<(), &str> = [Ok(()), Err("?"), Err("??")].into_iter().collect(); // Err("?") // And for Option<()> too: let _: Option<()> = [Some(()), Some(()), Some(())].into_iter().collect(); // Some(()) let _: Option<()> = [Some(()), None, None].into_iter().collect(); // None](https://pbs.twimg.com/media/E-qpFiFXMAE8VTH.jpg?name=small&format=webp)
ALT // () items can be collected into a single (), since it carries no information: let _: () = [(), (), (), (), ()].into_iter().collect(); // This also works for Result<(), E>, collecting the Ok(()) into a single Ok(()): let _: Result<(), &str> = [Ok(()), Ok(()), Ok(())].into_iter().collect(); // Ok(()) let _: Result<(), &str> = [Ok(()), Err("?"), Err("??")].into_iter().collect(); // Err("?") // And for Option<()> too: let _: Option<()> = [Some(()), Some(()), Some(())].into_iter().collect(); // Some(()) let _: Option<()> = [Some(()), None, None].into_iter().collect(); // None
![// Strings can be collected into a single concatenated string: let _: String = ["hello", " ", "world", "!"].into_iter().collect(); // "hello world!" // This also works from and to Cow<str>: let _: String = [Cow::Borrowed("hello "), Cow::Owned(123.to_string())].into_iter().collect(); // "hello 123" let _: Cow<str> = ["hello", " ", "🐄"].into_iter().collect(); // "hello 🐄" // OsStrs can be collected into an OsString: let _: OsString = [OsStr::new("/dev"), OsStr::new("/i2c-"), OsStr::new("1")].into_iter().collect(); // "/dev/i2c-1" // char codepoints can be encoded into an utf-8 String: let zwj = '\u{200d}'; let _: String = ['👩', zwj, '❤', '\u{fe0f}', zwj, '💋', zwj, '👩'].into_iter().collect(); // "👩❤️💋👩" // Paths are collected into a PathBuf by .join()'ing them as paths: let _: PathBuf = ["/", "home", "mara", "rust", "library"].into_iter().collect(); // "/home/mara/rust/library"](https://pbs.twimg.com/media/E-qqNv0XEAECrif.jpg?name=small&format=webp)
ALT // Strings can be collected into a single concatenated string: let _: String = ["hello", " ", "world", "!"].into_iter().collect(); // "hello world!" // This also works from and to Cow<str>: let _: String = [Cow::Borrowed("hello "), Cow::Owned(123.to_string())].into_iter().collect(); // "hello 123" let _: Cow<str> = ["hello", " ", "🐄"].into_iter().collect(); // "hello 🐄" // OsStrs can be collected into an OsString: let _: OsString = [OsStr::new("/dev"), OsStr::new("/i2c-"), OsStr::new("1")].into_iter().collect(); // "/dev/i2c-1" // char codepoints can be encoded into an utf-8 String: let zwj = '\u{200d}'; let _: String = ['👩', zwj, '❤', '\u{fe0f}', zwj, '💋', zwj, '👩'].into_iter().collect(); // "👩❤️💋👩" // Paths are collected into a PathBuf by .join()'ing them as paths: let _: PathBuf = ["/", "home", "mara", "rust", "library"].into_iter().collect(); // "/home/mara/rust/library"



























