Rohit Sachdeva
@_r_sachdeva
#Rust Senior Engineer: #Rustlang / #AsyncRust / #SystemDesign /#Backend / Cryptography / Machine Learning https://github.com/rsachdeva/drive-deposits
你可能會喜歡
Carl Lerche Presentation for #Rust #Rustlang Backend Developers -- Rust: A Productive Language for Writing Database Applications: infoq.com/presentations/…
infoq.com
Rust: a Productive Language for Writing Database Applications
Carl Lerche discusses Rust's potential as a productive language for building higher-level applications like web apps and backends, traditionally seen as performance-sensitive domains. He explains how...
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 趨勢
- 1. #CashAppPools 1,032 posts
- 2. Canada 426K posts
- 3. Reagan 189K posts
- 4. Reagan 189K posts
- 5. #ROGXboxAllyXSweepstakes N/A
- 6. Immigration 158K posts
- 7. Ashley 153K posts
- 8. #HaloWC 3,211 posts
- 9. West Ham 6,941 posts
- 10. Letitia James 60K posts
- 11. #FursuitFriday 15.7K posts
- 12. Kyler Gordon N/A
- 13. #WorldSeries 43.2K posts
- 14. Rod Wave 3,100 posts
- 15. Tish 14.6K posts
- 16. Revis N/A
- 17. Gerald R. Ford 18.4K posts
- 18. Chelsea 94.8K posts
- 19. Uncut Gems N/A
- 20. Tyrique Stevenson N/A
你可能會喜歡
-
Michael ORourke
@morourkej -
Ray Hartjen
@RayHartjen -
DeShaun’s Marketing, Inc.
@DeShaunsMrk -
Steven Connelly
@mkmmasconnelly1 -
Simon Hossell
@simonhossell -
GKL
@gklive1 -
JMax
@jarrodmax -
Maria Sigacheva, ACCA
@mariaxsigacheva -
Michael Altiero
@MichaelAltiero -
Unique Thoughts
@SEODummy1 -
Sushill Waddhwa
@WadhwaSushil -
UDAYAN MODHE
@umodhe
Something went wrong.
Something went wrong.