Class NativeHandleGuard

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    
    public class NativeHandleGuard
     implements AutoCloseable
                        

    Provides access to a Rust object handle while keeping the Java wrapper alive.

    Intended for use with try-with-resources syntax. NativeHandleGuard prevents the Java wrapper from being finalized, which would destroy the Rust object, while the handle is in use. To use it, the Java wrapper type should conform to the NativeHandleGuard.Owner interface.

    Note that it is not necessary to use NativeHandleGuard in the implementation of finalize itself. The point of NativeHandleGuard is to delay finalization while the Rust object is being used; once finalization has begun, there can be no other uses of the Rust object from Java.

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      long nativeHandle() Returns the native handle owned by the Java object, or 0 if the owner is null.
      void close()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • nativeHandle

         long nativeHandle()

        Returns the native handle owned by the Java object, or 0 if the owner is null.