These are chat archives for rust-lang/rust

May 2018
Berkus Decker
May 24 2018 00:33
@tandrysyawaludin you're welcome!
May 24 2018 02:13
error: unused dynamic parameter: `id`
  --> src/supplier_module/
24 | #[get("/<id>")]
why? even though i've used it
May 24 2018 02:24
ooh sorry that is my false, i forgot to use id in the function.
May 24 2018 04:54

Why is move out of dereference of raw pointer an error?

error[E0507]: cannot move out of dereference of raw pointer

The explanation at doesn't say anything about raw pointers.
I was trying to claim ownership of an instance of a #[repr(C)] struct MyObjectfor returning from MyObject::new().
A pointer to MyObject is returned by gobject_ffi::g_object_new().
I need to make sure that the g_object_ref() is called to increase reference count when Cloning and g_object_unref() is called when Dropping.

May 24 2018 06:17
@thefzsalam you can't take ownership of the value itself,
this can be helpful though.
May 24 2018 10:02
@thefzsalam you can do it with unsafe function std::ptr::read
But you should be sure that you not doing anything wrong

The problem with just

move out of dereference

is that when you dereference a pointer the value is borrowed

while std::ptr::read is the way to tell compiler "I really want to move the value from the pointer, I promise that the pointer will not be dereferenced (because it's UB) unless std::ptr::write is used to write new value there"
But from your explanation I see that this is not your case
Denis Lisov
May 24 2018 10:09
@thefzsalam What are you trying to do? Export a GObject API for a Rust object?
May 24 2018 11:23
@omni-viral, g_object_new() writes a value there. So I don't have to do std::ptr::write.
@tanriol, I don't want to export. I was building an implementation of GListModel for passing into gtk_list_bind_model
May 24 2018 12:11
@thefzsalam std::ptr::read is solution to get ownership of the object from raw pointer.
It is not valid for your use-case
What you can do is to make your own smart-pointer to call g_object_ref() and g_object_unref().
struct GPtr<T>(*mut T);

impl<T> Deref for GPtr<T> {
  type Target = T;
  fn deref(&self) -> &T {
    unsafe { &*self.0 }

impl<T> Clone for GPtr<T> {
  fn clone(&self) -> GPtr<T> {

impl<T> Drop for GPtr<T> {
  fn drop(&mut self) {
And MyObject::new will return GPtr<MyObject>
Probably someone already made such smart-pointer. You can look for it on
May 24 2018 12:18
Note that you cannot obtain &mut T from GPtr as it is semantically equivalent to Rc
So you may want to have another pointer type that 'owns' and object. That type will not be clonnable but convertible to clonnable GPtr
May 24 2018 12:46
That's what I was looking for.
What you can do is to make your own smart-pointer to call g_object_ref() and g_object_unref().
Thanks @omni-viral :)
Daniel Garrido
May 24 2018 16:06

hi all I am trying to run a simple example for the reqwest crate

fn main() {
    let text = reqwest::get("")?

    println!("body = {:?}", body);

..and I get this error

error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)

my setup:
cargo 0.26.0 (41480f5cc 2018-02-26)
rustc 1.25.0 (84203cac6 2018-03-25)
reqwest 0.8.5
any ideas?

Andrey Lesnikov
May 24 2018 16:08
update to rust 1.26 and try
fn main() -> Result<(), ()> {
    let text = reqwest::get("")?
    println!("body = {:?}", body);
or stay on rust 1.25 and wrap your code in a helper function returning result
Daniel Garrido
May 24 2018 16:16
Thanks @ozkriff I will update to 1.26 stable :)