I want to implement the code above, but had some problems:
(1) exepect code "self >> & mut rhs.value" directly return & mut Stream<'a> , but build follow err:
--> core/src/lib.rs:26:9
|
25 | fn shr(self, rhs: &'b mut ValueWrapper) -> Self::Output {
| ------------ expected &mut Stream<'_> because of return type
26 | self >> & mut rhs.value
| ^^^^^^^^^^^^^^^^^^^^^^^ expected &mut Stream<'_>, found associated type
|
(2) I try to write follow code, it still not working:
Then, to be honest I’m not sure to understand exactly what you are trying to achieve here, and implementing the Shr trait for Stream<'a> doesn’t sound right to me. What it means to perform a right shift of a value with the type T on a Stream? I feel Shr is not meant to be implemented like this. Maybe you can clarify exactly what you are trying to do, and we can suggest you a better approach.
That being said, here is one way to get this code to compile without error:
It would help if the was complete. I had to add use std::ops::Shr; and self >> & mut rhs.value to make the error.
I do not understand what you are trying to accomplish. StreamShr does not seem to do anything. I do not understand what you think self >> &mut rhs.value is meant to do.
If I guess about your intentions, I can get this to compile:
If you are attempting to make C++-style streams using << and >>, maybe do not. Abuse of operators like that is somewhat frowned upon in Rust. It is like making a function "divide_by_two" actually print "" to the console.
Thank you for your answer, You Guss is correct, I'm attempting to parse protocol filed from stream。at first I want to Implementing the Stream parsing framework。