News for hackers. Stuff that matters.
Re:Rust 0.9 released by Ygg2 on Thursday January 09, 2014 @04:18PM (#7033324)
Aren't unique pointer also scheduled for decommission?
Re:Rust 0.9 released by kibwen on Thursday January 09, 2014 @04:20PM (#7033345)
No, not at all. Unique pointers are awesome and are the foundation for lots of other features.

Now, some of the syntax for using them might still change. That's yet to be decided. But it wouldn't be Rust without unique pointers.

Re:Rust 0.9 released by tarpden on Thursday January 09, 2014 @11:21PM (#7035084)
Are "unique pointers" == "owned pointers"?
Re:Rust 0.9 released by Ygg2 on Friday January 10, 2014 @03:33AM (#7035709)
Sorry about the confusion, I just translate ~T as a Uniq<T> because they are unique (i.e. you can't use them without cloning) and they were called like that on a mailing list a few times (IIRC).
Re:Rust 0.9 released by dbaupp on Thursday January 09, 2014 @11:31PM (#7035109)
Yes, ~T.
Re:Rust 0.9 released by pcwalton on Thursday January 09, 2014 @04:42PM (#7033466)
Undecided. They will always be somewhat magical in that the "box" operator creates them by default. But the syntax for them may change, or be moved into the library.
Re:Rust 0.9 released by dded on Thursday January 09, 2014 @07:43PM (#7034297)
You can put a pointer type into a library?
Re:Rust 0.9 released by dbaupp on Thursday January 09, 2014 @08:18PM (#7034435)
Everything except the two reference types (& and &mut) can be trivially implemented in libraries: Rust is a low level language.

E.g. the following is almost exactly identical to `~T`

  #[unsafe_no_drop_flag]
  struct Uniq<T> { priv ptr: *mut T }

  impl<T> Uniq<T> {
      fn new(value: T) -> Uniq<T> {
          unsafe {
              let ptr = malloc(size_of::<T>()) as *mut T;
              if ptr.is_null() { fail!("malloc failed"); }

              move_val_init(&mut *ptr, value);
              Uniq { ptr: ptr }
          }
      }

      fn borrow<'a>(&'a self) -> &'a T {
          unsafe {&*self.ptr}
      }
      fn borrow_mut<'a>(&'a mut self) -> &'a mut T {
          unsafe {&mut *self.ptr}
      }
      fn move(mut self) -> T {
          unsafe {
              let v = ptr::read_ptr(self.ptr as *T);
              free(self.ptr);
              self.ptr = 0;
              v
          }
      }
  }
  #[unsafe_destructor]
  impl<T> Drop for Uniq<T> {
      fn drop(&mut self) {
          unsafe {
              // this will free the pointer and run the 
              // destructor of the inner type
              replace(self, transmute(0)).move();
          }
      }
  }
Re:Rust 0.9 released by lucian1900 on Thursday January 09, 2014 @08:04PM (#7034383)
Rc and Gc are now libraries you can import. A nice advantage is that Arc, MutexArc and any other reference types look and work the same way.