feat(conversions): add hint comments
This commit is contained in:
parent
8cfedb1673
commit
74f44f55e3
|
@ -1,6 +1,8 @@
|
||||||
// The From trait is used for value-to-value conversions.
|
// The From trait is used for value-to-value conversions.
|
||||||
// If From is implemented correctly for a type, the Into trait should work conversely.
|
// If From is implemented correctly for a type, the Into trait should work conversely.
|
||||||
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.From.html
|
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.From.html
|
||||||
|
// Execute `rustlings hint from_into` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Person {
|
struct Person {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
// Additionally, upon implementing FromStr, you can use the `parse` method
|
// Additionally, upon implementing FromStr, you can use the `parse` method
|
||||||
// on strings to generate an object of the implementor type.
|
// on strings to generate an object of the implementor type.
|
||||||
// You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html
|
// You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html
|
||||||
|
// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -37,6 +39,9 @@ enum ParsePersonError {
|
||||||
// with something like `"4".parse::<usize>()`
|
// with something like `"4".parse::<usize>()`
|
||||||
// 6. If while extracting the name and the age something goes wrong, an error should be returned
|
// 6. If while extracting the name and the age something goes wrong, an error should be returned
|
||||||
// If everything goes well, then return a Result of a Person object
|
// If everything goes well, then return a Result of a Person object
|
||||||
|
//
|
||||||
|
// As an aside: `Box<dyn Error>` implements `From<&'_ str>`. This means that if you want to return a
|
||||||
|
// string error message, you can do so via just using return `Err("my error message".into())`.
|
||||||
|
|
||||||
impl FromStr for Person {
|
impl FromStr for Person {
|
||||||
type Err = ParsePersonError;
|
type Err = ParsePersonError;
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
// Basically, this is the same as From. The main difference is that this should return a Result type
|
// Basically, this is the same as From. The main difference is that this should return a Result type
|
||||||
// instead of the target type itself.
|
// instead of the target type itself.
|
||||||
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
||||||
|
// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
//
|
//
|
||||||
// The goal is to make sure that the division does not fail to compile
|
// The goal is to make sure that the division does not fail to compile
|
||||||
// and returns the proper type.
|
// and returns the proper type.
|
||||||
|
// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue