惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
G
Google Developers Blog
WordPress大学
WordPress大学
M
MIT News - Artificial intelligence
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
I
InfoQ
MyScale Blog
MyScale Blog
V
V2EX
B
Blog
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Review: Static Multi Pool Allocator Rmquickjs - High-level MicroQuickJS bindings for Rust
C++ to Rust -- Exceptions
@AndrewOfC A · 2026-04-24 · via The Rust Programming Language Forum - Latest posts
C++ Exceptions One underappreciated feature of C++ is the ability to throw/catch exceptions. If one leverages the flexability of using different classes to represent different use-cases of 'exceptional behavior' a robust, readble, and extensible error handling system can be created and maintained. A best practice is to create classes of exception that will capture as much infomation about the cause of the exception before the actual 'throw' and to use that to provide the user or higher level developer with a more meaningful error message. try { MyObj.myOperation() } catch ( const FileNotFound& e ) { } catch ( const IllegalConfigurationException& e ) { } catch ( const SyntaxException& e ) { } catch (const std::exception& e) { } catch (...) { } Rust Rust, on the other hand, eschews exceptions. However, there is a feature in Rust that can be leveraged to create a similar pattern for error handling and provide much of the same of the same benefits using enums and the sugary '?' operator. Enums enum ErrorCases { FileNotFound(String), // provide expected path of the missing file IllegalConfiguration, SyntaxError(u32/*line*/, u32/*column*/, String/*file*/), Other(String), } fn my_file_operation(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::FileNotFound("my_file.txt".to_string())) } else { Ok(()) } } fn my_syntax_error(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::SyntaxError(10, 20, "my_file.txt".to_string())) } else { Ok(()) } } fn my_config_operation(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::IllegalConfiguration) } else { Ok(()) } } fn my_other_operation(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::Other("Unexpected error".to_string())) } else { Ok(()) } } fn my_operation() -> Result<(), ErrorCases> { my_file_operation(false)?; my_syntax_error(true)?; my_config_operation(false)?; my_other_operation(false)?; Ok(()) } fn main() { match my_operation() { Ok(_) => println!("Success"), Err(ErrorCases::FileNotFound(path)) => println!("File not found: {path}"), Err(ErrorCases::IllegalConfiguration) => println!("Illegal configuration"), Err(ErrorCases::SyntaxError(line, column, file)) => println!("Syntax error on line {line} column {column} in file {file}"), Err(ErrorCases::Other(msg)) => println!("Other error: {msg}"), } ; } This can also ensure thorough error handling. Introducing a new error case will trigger the compiler to warn that the error needs to be handled. Provided of course that we do not use the 'wildcard' pattern to catch unknowns.