New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
&'a Headers does not allow reading Headers #47
Comments
Oh right, because it needs to be mutable internally. Maybe Headers could That would also improve fighting the borrowck in matches. |
RefCell would not be a good solution here as it would be a leaky abstraction and lead to runtime failures when code tries to get two header references with overlapping lifetimes - this code would fail, for instance: let length = req.headers.get_ref::<ContentLength>();
let encoding = req.headers.get_ref::<TransferEncoding>(); Right now this is a compile-time failure, using RefCell would make it a runtime failure. We would also have to return |
This removes the need to receive `&mut self` in `get_ref` and `get.` Since the interior mutability of the RWLock is needed only once, it is safe to change the lifetime of the pointer given by read locks as by then all mutation has been done. Since `set` still requires `&mut self` there is no way to use the interior mutability of the RWLock to modify an existing `&`-reference. However, the use of interior mutability in `get_ref` means that `get_raw` is now actually an unsafe operation because the (now `*const`) pointer could be invalidated by a subsequent call to `get_ref.` Fixes hyperium#47
Basically scratch the above, I did crazy things with RWLock in #48 that fixes this and more. |
This removes the need to receive `&mut self` in `get_ref` and `get.` Since the interior mutability of the RWLock is needed only once, it is safe to change the lifetime of the pointer given by read locks as by then all mutation has been done. Since `set` still requires `&mut self` there is no way to use the interior mutability of the RWLock to modify an existing `&`-reference. However, the use of interior mutability in `get_ref` means that `get_raw` is now actually an unsafe operation because the (now `*const`) pointer could be invalidated by a subsequent call to `get_ref.` Fixes hyperium#47
This removes the need to receive `&mut self` in `get_ref` and `get.` Since the interior mutability of the RWLock is needed only once, it is safe to change the lifetime of the pointer given by read locks as by then all mutation has been done. Since `set` still requires `&mut self` there is no way to use the interior mutability of the RWLock to modify an existing `&`-reference. However, the use of interior mutability in `get_ref` means that `get_raw` is now actually an unsafe operation because the (now `*const`) pointer could be invalidated by a subsequent call to `get_ref.` Fixes hyperium#47
I've got a branch implementing a
HeadersView
that solves this problem, but right now that means you can't read the Headers of anythingStreaming
.The text was updated successfully, but these errors were encountered: