diff --git a/src/data/roadmaps/rust/content/102-error-handling/100-option.md b/src/data/roadmaps/rust/content/102-error-handling/100-option.md index 0eabfd79c..a75fab0ef 100644 --- a/src/data/roadmaps/rust/content/102-error-handling/100-option.md +++ b/src/data/roadmaps/rust/content/102-error-handling/100-option.md @@ -1,3 +1,8 @@ # Option & Result Enumerations -`Option` is an enumeration, also known as an `enum`, in Rust with two variants: `Some(T)` and `None`. It is a flexible and safe alternative to using `null` values or exceptions for indicating that a value might not be present. If a function may not return a value for all possible input, it should return an `Option` value. `Some(T)` variant contains the valid value of type `T` and `None` variant indicates the absence of a value. You can perform various operations on `Option` values, such as method chaining and pattern matching, to effectively handle both states (value present or absent). The `Option` enum encourages you to consciously deal with the possibility of missing values and helps prevent unforeseen runtime errors. \ No newline at end of file +`Option` is an enumeration, also known as an `enum`, in Rust with two variants: `Some(T)` and `None`. It is a flexible and safe alternative to using `null` values or exceptions for indicating that a value might not be present. If a function may not return a value for all possible input, it should return an `Option` value. `Some(T)` variant contains the valid value of type `T` and `None` variant indicates the absence of a value. You can perform various operations on `Option` values, such as method chaining and pattern matching, to effectively handle both states (value present or absent). The `Option` enum encourages you to consciously deal with the possibility of missing values and helps prevent unforeseen runtime errors. + +Visit the following resources to learn more: + +- [@article@Rust by Example: Option & unwrap](https://doc.rust-lang.org/rust-by-example/error/option_unwrap.html) +- [@article@Rust by Example: Result](https://doc.rust-lang.org/rust-by-example/error/result.html) diff --git a/src/data/roadmaps/rust/content/102-error-handling/101-propagating.md b/src/data/roadmaps/rust/content/102-error-handling/101-propagating.md index 297fba83b..1cf2bb0eb 100644 --- a/src/data/roadmaps/rust/content/102-error-handling/101-propagating.md +++ b/src/data/roadmaps/rust/content/102-error-handling/101-propagating.md @@ -1,3 +1,7 @@ # Propagating Errors and `?` Operator -Propagating errors in Rust is about passing the error information from the function that failed to the function that called it. Using the `?` operator is one way to achieve this. This operator can only be used in functions that return `Result` or `Option` or another type that implements `std::ops::Try`. If the value of the `Result` is `Ok`, the value inside the `Ok` will get returned. If the value is `Err`, the `Err` will be returned from the whole function. Consequently, the error gets propagated to the calling function. \ No newline at end of file +Propagating errors in Rust is about passing the error information from the function that failed to the function that called it. Using the `?` operator is one way to achieve this. This operator can only be used in functions that return `Result` or `Option` or another type that implements `std::ops::Try`. If the value of the `Result` is `Ok`, the value inside the `Ok` will get returned. If the value is `Err`, the `Err` will be returned from the whole function. Consequently, the error gets propagated to the calling function. + +Visit the following resources to learn more: + +- [@article@Rust Book: Recoverable Errors with Result](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html) diff --git a/src/data/roadmaps/rust/content/102-error-handling/102-custom-error.md b/src/data/roadmaps/rust/content/102-error-handling/102-custom-error.md index 909a6319d..ad42fc3ad 100644 --- a/src/data/roadmaps/rust/content/102-error-handling/102-custom-error.md +++ b/src/data/roadmaps/rust/content/102-error-handling/102-custom-error.md @@ -1,3 +1,7 @@ # Custom Error Types and Traits -In Rust, you can define your own types of errors using the `enum` construct. This gives you the ability to specify different types of errors that your code can encounter, and attach additional information to them. To make your custom error type compatible with the rest of Rust's error handling machinery, you need to implement two traits: `std::fmt::Debug` and `std::fmt::Display`. There is also a third trait, `std::error::Error`, which can provide backtraces and the ability to have chained errors or causes. Furthermore, the `thiserror` library provides a convenient way to define custom error types with a simple annotation. \ No newline at end of file +In Rust, you can define your own types of errors using the `enum` construct. This gives you the ability to specify different types of errors that your code can encounter, and attach additional information to them. To make your custom error type compatible with the rest of Rust's error handling machinery, you need to implement two traits: `std::fmt::Debug` and `std::fmt::Display`. There is also a third trait, `std::error::Error`, which can provide backtraces and the ability to have chained errors or causes. Furthermore, the `thiserror` library provides a convenient way to define custom error types with a simple annotation. + +Visit the following resources to learn more: + +- [@article@Rust by Example: Defining an error type](https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/define_error_type.html)