Ad
  • Custom User Avatar

    Funny, this undef_method delegates #== and #! to @obj and makes this the shortest solution!

  • Custom User Avatar

    ||= with begin … end seems like a concise way to do more complex lazy initialization!
    And I never considered ending a .each with && nil if it's the last expression in a method.

  • Custom User Avatar

    and thus can change that value by performing operations on the pointer?

    Yes. &mut res creates a mutable reference, and passing it to reduce makes a mutable borrow.
    It is still checked by Rust's borrow checker with even more stringent rules to avoid having multiple mutable references to a value or a shared reference (&) and a mutable reference to the same value.

    Meanwhile, I'm reading in the book (19.1. Unsafe Rust » Dereferencing a Raw Pointer) that in unsafe Rust it's possible to create and dereference "raw pointers" where the above restrictions don't apply.