diff options
| author | Teddy Wing | 2020-06-27 20:07:22 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2020-06-27 20:07:22 +0200 | 
| commit | 81402cc311ae075d036759cabab829f61fd216be (patch) | |
| tree | 1e219d89fbfbddd1d9df0993a79392f5bf94f28b | |
| parent | b8ac72f1fb4b6e3e0575e212bf6138e20bd9bdff (diff) | |
| download | fastcgi-conduit-81402cc311ae075d036759cabab829f61fd216be.tar.bz2 | |
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
| -rw-r--r-- | src/lib.rs | 45 | 
1 files changed, 28 insertions, 17 deletions
| @@ -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<u64> { 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<u64> { 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; | 
