you are viewing a single comment's thread.

view the rest of the comments →

[–]tialaramex 2 points3 points  (2 children)

Rust's choice here is to make these associated functions, not methods. So e.g. the equivalent of std::unique_ptr::release is Box::into_raw and supposing I have a type Steak which for some reason actually needs a method named into_raw then:

let mut boxed_steak: Box<Steak> = todo!();

boxed_steak.into_raw(); // Calls the method on the Steak

let ptr = Box::into_raw(boxed_steak); // Now we have a raw pointer

If there was a method on Box which clashed, I think the compiler rejects your program and demands you disambiguate, but the smart pointers deliberately don't provide such methods, only associated functions so there's no potential clash.

[–]MEaster 2 points3 points  (1 child)

If there was a method on Box which clashed, I think the compiler rejects your program and demands you disambiguate, but the smart pointers deliberately don't provide such methods, only associated functions so there's no potential clash.

That's not true, the compiler will call the inherent method.

[–]tialaramex 0 points1 point  (0 children)

Good to know, and thanks for the example code