Rohit Sachdeva
@_r_sachdeva
#Rust Senior Engineer: #Rustlang / #AsyncRust / #SystemDesign /#Backend / Cryptography / Machine Learning https://github.com/rsachdeva/drive-deposits
Tal vez te guste
Carl Lerche Presentation for #Rust #Rustlang Backend Developers -- Rust: A Productive Language for Writing Database Applications: infoq.com/presentations/…
Rust 1.85.0 has been released! 🌈🦀✨ Not only does this release add async closures, it also includes a whole new Rust Edition, Rust 2024! 🎆🚀 Check out the blog post for an overview of all the changes and additions: blog.rust-lang.org/2025/02/20/Rus…
Track #Rust releases from: releases.rs release-monitoring.org/project/7635/ github.com/rust-lang/rust… #Rustlang
An async function, when called, returns a Future because the Future is return type. This is just returning its return type like any regular function. The only change is Future wraps the declared return type in async function, to make the full return. #asyncrust
Rust Range Counting: (low..=high).count() vs (high-low) + 1 Both are equally fast - Range's count() uses optimized arithmetic under the hood. No iteration one by one in count. Calculates the number of steps between start and end using Step::steps_between! #Rust #Rustlang
match some_string.as_str() { "hello" => println!("Found hello"), _ => println!("Something else") } Pattern Match: doc.rust-lang.org/reference/patt… shows String literals which are of &str type, not String. You can directly use "hello" but not "hello".to_string(). #rust #rustlang
get() method: Vec vs String // Vec get signature has: I: SliceIndex<[T]> // String get signature has: I: SliceIndex<str> impl SliceIndex: Vec ([T]): single index (usize) and ranges String (str): Only ranges even for one character[s.get(0..1)] due to UTF-8 #Rust #Rustlang
The turbofish follows one consistent pattern: ::<T> where T is your type parameter. "42".parse::<i32>(); Turbofish portion: ::<i32> Vec::<Vec<u8>>::new() Turbofish portion: ::<Vec<u8>> Associated function call: ::new() Creates a vector holding byte vectors #rust #rustlang
// Instead of match result { // Ok(val) => val, // Err(_) => compute_default() // } let value = result.unwrap_or_else(|_| compute_default()); // Instead match result { // Ok(val) => val, // Err(_) => Default::default() // } let value = result.unwrap_or_default(); #Rust #Rustlang
Refutable Dictionary meaning: 'capable of being proved false'. Such patterns can hence ONLY be used in: - if let expressions - while let expressions - match arms expressions (except the last arm which must be irrefutable) - let...else statements #Rust #Rustlang
In #Rust traits: Definition: Self: Unknown type self: Future instance of unknown type Self Implementation: Self: Becomes concrete implementing type self: Becomes instance of implementing type Note: self is shorthand for self: Self #Rustlang
For From trait: What comes after `for` is the TARGET type What's in angle brackets is what we're converting FROM For Deref trait: What comes after `for` is what we're converting FROM Target type is specified in associated type (type Target = ) #Rust #Rustlang
HashMap #rustlang fn and_modify<F>(self, f: F) -> Self where F: FnOnce(&mut V) Closure's return type F: FnOnce(&mut V) returns () Function and_modify's return type -> Self Two returns different purposes:closure return is for modification, function's return enables fluent API
Less Common Uses of ? and !: ?Sized in Trait Bounds: struct Container<T: ?Sized> { data: Box<T> } // Allows both sized/unsized ! in Trait Implementations: impl !Send for MyType {} // non-thread-safe Common: ? for error handling ! for declarative macros #Rustlang
fn execute(writer_half: OwnedWriteHalf) { let mut writer = writer_half; // And Reads very naturally in the code that follows } // 〰️ // Same as fn execute(mut writer_half: OwnedWriteHalf) { } Choose by Readability. #Rust #Rustlang
&str TYPE size is always 16 bytes (fat ptr) DATA size varies by content let s = String::from("Hello"); let slice = &s[1..]; // "ello" println!("Type: {}, Data: {}", std::mem::size_of::<&str>(), std::mem::size_of_val(slice)); // 4 #Rustlang #Rust
let owned = String::from("world"); let y : Option<&str> = owned.get(1..3); let text = "hello"; let z: Option<&str> = text.get(1..3); Type annotations are just added to show slice &str. So get supports range as input. Returns slice. #Rust #Rustlang
United States Tendencias
- 1. Mendoza 13.8K posts
- 2. Penn State 15.4K posts
- 3. Gus Johnson 3,148 posts
- 4. Omar Cooper 3,203 posts
- 5. Sunderland 139K posts
- 6. $SSHIB 1,465 posts
- 7. #iufb 2,515 posts
- 8. Jim Knowles N/A
- 9. James Franklin 5,505 posts
- 10. Texas Tech 11.5K posts
- 11. Arsenal 238K posts
- 12. Happy Valley 1,167 posts
- 13. WHAT A CATCH 8,899 posts
- 14. St. John 7,674 posts
- 15. Jeremiah Smith 2,244 posts
- 16. Sayin 62K posts
- 17. Charlie Becker N/A
- 18. CATCH OF THE YEAR 2,151 posts
- 19. #GoDawgs 4,294 posts
- 20. Raya 27.5K posts
Tal vez te guste
Something went wrong.
Something went wrong.