pub fn try_with<R, F: FnOnce(&T) -> R>(&self, f: F) -> Result<R, AccessError> {
        let ptr = unsafe { oskey::get(self.key) as *mut ThreadLocalValue<T> };
        let value = NonNull::new(ptr).unwrap_or_else(|| unsafe {
            // Equivalent to currently unstable Box::into_raw_non_null.
            // https://github.com/rust-lang/rust/issues/47336#issuecomment-373941458
            let result = NonNull::new_unchecked(Box::into_raw(Box::new(ThreadLocalValue {
                inner: (self.init)(),
                key: self.key,
            })));
            oskey::set(self.key, result.as_ptr() as *mut _);
            result
        });
        // Avoid reinitializing a TLS that was destroyed.
        if value != GUARD.cast() {
            Ok(f(&unsafe { value.as_ref() }.inner))
        } else {
            Err(AccessError { _private: () })
        }
    }
/// Acquires a reference to the value in this thread-local storage.
///
/// This will lazily initialize the value if this thread has not accessed it
/// yet. If the storage has been destroyed, this function will return an
/// `AccessError`.
///
/// ```rust
/// use os_thread_local::ThreadLocal;
/// use std::cell::Cell;
///
/// let tls = ThreadLocal::new(|| Cell::new(42));
/// tls.try_with(|v| v.set(21)).expect("storage destroyed");
/// ```
///
/// # Panics
///
/// This function will `panic!()` if the storage is uninitialized and the
/// initializer given to [`ThreadLocal::new`](#method.new) panics.
/// This function can also `panic!()` if the storage is uninitialized and there
/// is not enough available memory to allocate a new thread local storage for
/// the current thread, or if the OS primitives fail.
Acquires a reference to the value in this thread-local storage.
This will lazily initialize the value if this thread has not accessed it
yet. If the storage has been destroyed, this function will return an
`AccessError`.




Acquires a reference to the value in this thread - local storage . This will lazily initialize the value if this thread has not accessed it yet . If the storage has been destroyed this function will return an ` AccessError ` .
pub fn try_with<R, F: FnOnce(&T) -> R>(&self, f: F) -> Result<R, AccessError> {
        let ptr = unsafe { oskey::get(self.key) as *mut ThreadLocalValue<T> };
        let value = NonNull::new(ptr).unwrap_or_else(|| unsafe {
            // Equivalent to currently unstable Box::into_raw_non_null.
            // https://github.com/rust-lang/rust/issues/47336#issuecomment-373941458
            let result = NonNull::new_unchecked(Box::into_raw(Box::new(ThreadLocalValue {
                inner: (self.init)(),
                key: self.key,
            })));
            oskey::set(self.key, result.as_ptr() as *mut _);
            result
        });
        // Avoid reinitializing a TLS that was destroyed.
        if value != GUARD.cast() {
            Ok(f(&unsafe { value.as_ref() }.inner))
        } else {
            Err(AccessError { _private: () })
        }
    }
pub fn try_with < R , F : FnOnce ( & T ) -> R > ( & self , f : F ) -> Result < R , AccessError > { let ptr = unsafe { oskey :: get ( self . key ) as * mut ThreadLocalValue < T > } ; let value = NonNull :: new ( ptr ) . unwrap_or_else ( | | unsafe { // Equivalent to currently unstable Box::into_raw_non_null. // https://github.com/rust-lang/rust/issues/47336#issuecomment-373941458 let result = NonNull :: new_unchecked ( Box :: into_raw ( Box :: new ( ThreadLocalValue { inner : ( self . init ) ( ) , key : self . key , } ) ) ) ; oskey :: set ( self . key , result . as_ptr ( ) as * mut _ ) ; result } ) ; // Avoid reinitializing a TLS that was destroyed. if value != GUARD . cast ( ) { Ok ( f ( & unsafe { value . as_ref ( ) } . inner ) ) } else { Err ( AccessError { _private : ( ) } ) } }
Acquires a reference to the value in this thread-local storage.
Acquires a reference to the value in this thread - local storage .
&self
f
F
&self
f
F
panics
This function will `panic!()` if the storage is uninitialized and the
initializer given to [`ThreadLocal::new`](#method.new) panics.
This function can also `panic!()` if the storage is uninitialized and there
is not enough available memory to allocate a new thread local storage for
the current thread, or if the OS primitives fail.
This function will ` panic! () ` if the storage is uninitialized and the initializer given to [ ` ThreadLocal :: new ` ] ( #method . new ) panics . This function can also ` panic! () ` if the storage is uninitialized and there is not enough available memory to allocate a new thread local storage for the current thread or if the OS primitives fail .