Notes for book of Effective Rust

#notes #rust

Charpter8

Charpter4

Mutual error types

If you want to mutually create a error type, some trait should be implemented by yourself.

Effective Rust, page 34

Enum type to represent multi errors

Effective Rust, page 35

Effective Rust, page 37

If you want to implement the different upstream errors to concrate MyError, a fair amount of boilerplate should be added. But the crate of thiserror solves this.

Charpter3

The methods for Result or Option

Pasted image 20240531113322.png

The syntactic surgar of ?

But explicitly convertion may be not necessary if the external error has implemented the From trait for the internal Error type.

Pasted image 20240531113012.png
Pasted image 20240531113032.png

Charpter2

Closures catch external variant

Pasted image 20240531112036.png

The difference with function and method

Pasted image 20240531111246.png

What's the meaning of self or &self or &mut self

Pasted image 20240531111024.png