These are chat archives for rust-lang/rust

15th
Aug 2018
I'm having trouble passing an Arc<MyStruct> into C code and back. I get a crash when using one of the fields after it's made the round-trip:
struct MyStruct {
    lock: RwLock<i32>
}

fn make_struct() -> *const MyStruct {
    let arc = Arc::new(MyStruct { lock: RwLock::new(5) });
    Arc::into_raw(arc)
}

fn do_something_with_struct(arc: *const MyStruct) {
    let arc = unsafe { Arc::from_raw(arc) };
    let writer = arc.lock.write().unwrap(); // crashes
}
Lyle Mantooth
@IslandUsurper
Aug 15 2018 14:00
@jnicholls, in the meta attribute, try using stringify!($result_type), if you can't just use $result_type there.
(I am not an expert, though.)
Sylwester Rąpała
@xoac
Aug 15 2018 21:50

I have issue with lifetime that I don't understand:

      /// Consume builder and execute request.
      fn send<'a, T>(self, req_body: Body) -> impl Future<Item = T, Error = Error>
      where
          T: Deserialize<'a>,
      {
          let req = self.body(req_body);

          Client::new()
              .request(req)
              .and_then(|res| {
                  let status = res.status();
                  res.into_body().concat2().map(move |bytes| (status, bytes))
              })
              .from_err::<Error>()
              .and_then(move |(status, res_bytes)| {
                  if status != StatusCode::OK {
                      let info = serde_json::from_slice(&res_bytes)?;
                      Ok(info)
                  } else {
                      Err(Error::from_status_and_body(status, &res_bytes))
                  }
              })
              .from_err()
      }

I was created this function looking on declartion forserde_json::from_slice..

error[E0597]: `res_bytes` does not live long enough
   --> src/client/builders.rs:112:56
    |
112 |                     let info = serde_json::from_slice(&res_bytes)?;
    |                                                        ^^^^^^^^^ borrowed value does not live long enough
...
117 |             })
    |             - borrowed value only lives until here
    |
note: borrowed value must be valid for the lifetime 'a as defined on the method body at 97:5...
   --> src/client/builders.rs:97:5
    |
97  | /     fn send<'a, T>(self, req_body: Body) -> impl Future<Item = T, Error = Error>
98  | |     where
99  | |         T: Deserialize<'a>,
100 | |     {
...   |
118 | |             .from_err()
119 | |     }
    | |_____^
Denis Lisov
@tanriol
Aug 15 2018 21:53
How about removing 'a and replacing Deserialize<'a> with DeserializeOwned?
Sylwester Rąpała
@xoac
Aug 15 2018 21:54
@tanriol How about you rethinking about beer? :P
Thx that seems to work
Denis Lisov
@tanriol
Aug 15 2018 22:00
@xoac Thank you, but alcohol is not my cup of tea :-)
Tom Budd
@tom__budd_twitter
Aug 15 2018 23:27
Does anyone know how I can create a url path to a message on gitter?