Hello,
I am trying to make sense of this piece of code
pub fn can_write_head(&self) -> bool {
if !T::should_read_first() { // <--- I don't understand what's happening here.
if let Reading::Closed = self.state.reading {
return false;
}
}
match self.state.writing {
Writing::Init => true,
_ => false,
}
}
Basically, the type T has to implement the trait Http1Transaction, but that field is not present in neither the struct definition nor the instanciation method (using the Conn::new(io: I) struct building method).
pub(crate) struct Conn<I, B, T> {
io: Buffered<I, EncodedBuf<B>>,
state: State,
_marker: PhantomData<fn(T)>,
}
It is wrapped inside a PhantomData marker, as the function's pointer's only argument.
Here is the file where it is implemented.
Also, the file where the Conn struct is used with that T::should_error_on_parse_eof() syntax.
I guess that the compiler will choose either options, but I still don't understand how that would work. If someone is familiar with the hyper source code and could help me out with this, I've already spent a good amount of time trying to figure it out.
-
Client::should_error_on_parse_eof()
-
Server::should_error_on_parse_eof()
How does the code "know" which one to use? I am reverse engineering the Client code examples but I just don't know where in the code that check happens (to decide to either use the Client or Server implementation).
Maybe someone is familiar with hyper's source code and can point me out in the right direction.
Thank you in advance,