File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,27 @@ All errors should be handled in one of these ways:
78
78
- With ` .log_err().ok() ` .
79
79
- Bubbled up with ` ? ` .
80
80
81
+ When working with [ async streams] ( https://docs.rs/futures/0.3.31/futures/stream/index.html ) ,
82
+ prefer [ ` try_next ` ] ( https://docs.rs/futures/0.3.31/futures/stream/trait.TryStreamExt.html#method.try_next ) over ` next() ` , e.g. do
83
+ ```
84
+ while let Some(event) = stream.try_next().await? {
85
+ todo!();
86
+ }
87
+ ```
88
+ instead of
89
+ ```
90
+ while let Some(event_res) = stream.next().await {
91
+ todo!();
92
+ }
93
+ ```
94
+ as it allows bubbling up the error early with ` ? `
95
+ with no way to accidentally skip error processing
96
+ with early ` continue ` or ` break ` .
97
+ Some streams reading from a connection
98
+ return infinite number of ` Some(Err(_)) `
99
+ items when connection breaks and not processing
100
+ errors may result in infinite loop.
101
+
81
102
` backtrace ` feature is enabled for ` anyhow ` crate
82
103
and ` debug = 1 ` option is set in the test profile.
83
104
This allows to run ` RUST_BACKTRACE=1 cargo test `
You can’t perform that action at this time.
0 commit comments