From 81402cc311ae075d036759cabab829f61fd216be Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 27 Jun 2020 20:07:22 +0200 Subject: FastCgiRequest: Start implementing `conduit::RequestExt` Was getting this error about the lifetimes in the trait impl: error[E0308]: method not compatible with trait --> src/lib.rs:137:4 | 137 | fn host(&'a self) -> conduit::Host<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch | = note: expected fn pointer `fn(&'a FastCgiRequest<'static>) -> conduit::Host<'a>` found fn pointer `fn(&'a FastCgiRequest<'static>) -> conduit::Host<'a>` note: the lifetime `'a` as defined on the method body at 137:4... --> src/lib.rs:137:4 | 137 | fn host(&'a self) -> conduit::Host<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 124:6 --> src/lib.rs:124:6 | 124 | impl<'a> conduit::RequestExt for FastCgiRequest { | ^^ error[E0308]: method not compatible with trait --> src/lib.rs:137:4 | 137 | fn host(&'a self) -> conduit::Host<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch | = note: expected fn pointer `fn(&'a FastCgiRequest<'static>) -> conduit::Host<'a>` found fn pointer `fn(&'a FastCgiRequest<'static>) -> conduit::Host<'a>` note: the lifetime `'a` as defined on the impl at 124:6... --> src/lib.rs:124:6 | 124 | impl<'a> conduit::RequestExt for FastCgiRequest { | ^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the method body at 137:4 --> src/lib.rs:137:4 | 137 | fn host(&'a self) -> conduit::Host<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Learned from these resources that the problem arose because the `impl` uses an `'a` lifetime, but the lifetime on the `host()` method need to be a different one: https://github.com/rust-lang/rust/issues/56423 https://stackoverflow.com/questions/24847331/rust-lifetime-error-expected-concrete-lifetime-but-found-bound-lifetime/24848424#24848424 --- src/lib.rs | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index d237bab..98dcba7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,23 +121,34 @@ impl<'a> FastCgiRequest<'a> { } } -// impl<'a> conduit::RequestExt for FastCgiRequest { -// fn http_version(&self) -> conduit::Version { todo!() } -// fn method(&self) -> &conduit::Method { -// self.method -// } -// fn scheme(&self) -> conduit::Scheme { todo!() } -// fn host(&'a self) -> conduit::Host<'a> { todo!() } -// fn virtual_root(&'a self) -> std::option::Option<&'a str> { todo!() } -// fn path(&'a self) -> &'a str { todo!() } -// fn query_string(&'a self) -> std::option::Option<&'a str> { todo!() } -// fn remote_addr(&self) -> std::net::SocketAddr { todo!() } -// fn content_length(&self) -> std::option::Option { todo!() } -// fn headers(&self) -> &conduit::HeaderMap { todo!() } -// fn body(&'a mut self) -> &'a mut (dyn std::io::Read + 'a) { todo!() } -// fn extensions(&'a self) -> &'a conduit::TypeMap { todo!() } -// fn mut_extensions(&'a mut self) -> &'a mut conduit::TypeMap { todo!() } -// } +impl<'a> conduit::RequestExt for FastCgiRequest<'a> { + fn http_version(&self) -> conduit::Version { + self.http_version + } + + fn method(&self) -> &conduit::Method { + &self.method + } + + fn scheme(&self) -> conduit::Scheme { + self.scheme() + } + + fn host<'b>(&'b self) -> conduit::Host<'b> { + conduit::Host::Name(&self.host) + } + + fn virtual_root<'b>(&'b self) -> std::option::Option<&'b str> { todo!() } + + fn path<'b>(&'b self) -> &'b str { todo!() } + fn query_string<'b>(&'b self) -> std::option::Option<&'b str> { todo!() } + fn remote_addr<'b>(&self) -> std::net::SocketAddr { todo!() } + fn content_length<'b>(&self) -> std::option::Option { todo!() } + fn headers<'b>(&self) -> &conduit::HeaderMap { todo!() } + fn body<'b>(&'b mut self) -> &'b mut (dyn std::io::Read + 'b) { todo!() } + fn extensions<'b>(&'b self) -> &'b conduit::TypeMap { todo!() } + fn mut_extensions<'b>(&'b mut self) -> &'b mut conduit::TypeMap { todo!() } +} struct Server; -- cgit v1.2.3