pub fn take_downcast<T>(self) -> Result<T, AccessError>
    where
        T: Any,
    {
        // Safety: We know that interior value is alive since this container is
        // alive.
        //
        // Appropriate access is checked when constructing the guards.
        unsafe {
            let inner = self.inner.as_ref();

            // NB: don't drop guard to avoid yielding access back.
            // This will prevent the value from being dropped in the shared
            // destructor and future illegal access of any kind.
            let guard = ManuallyDrop::new(inner.access.take(AccessKind::Any)?);

            // Read the pointer out without dropping the inner structure.
            // Note that the data field will after this point be invalid.
            //
            // Future access is forever prevented since we never release
            // exclusive access (see above).
            let any = ptr::read(inner.data.get());

            let expected = Hash::from_type_id(any::TypeId::of::<T>());

            let (e, any) = match any.raw_take(expected) {
                Ok(value) => return Ok(*Box::from_raw(value as *mut T)),
                Err((AnyObjError::Cast, any)) => {
                    let actual = any.type_name();

                    let e = AccessError::UnexpectedType {
                        actual,
                        expected: any::type_name::<T>().into(),
                    };

                    (e, any)
                }
                Err((e, any)) => (e.into(), any),
            };

            // At this point type coercion has failed for one reason or another,
            // so we reconstruct the state of the Shared container so that it
            // can be more cleanly dropped.

            // Drop the guard to release exclusive access.
            drop(ManuallyDrop::into_inner(guard));

            // Write the potentially modified value back so that it can be used
            // by other `Shared<T>` users pointing to the same value. This
            // conveniently also avoids dropping `any` which will be done by
            // `Shared` as appropriate.
            ptr::write(inner.data.get(), any);
            Err(e)
        }
    }
/// Take the interior value, if we have exlusive access to it and there
/// exist no other references.
Take the interior value, if we have exlusive access to it and there
exist no other references.
Take the interior value if we have exlusive access to it and there exist no other references .
pub fn take_downcast<T>(self) -> Result<T, AccessError>
    where
        T: Any,
    {
        // Safety: We know that interior value is alive since this container is
        // alive.
        //
        // Appropriate access is checked when constructing the guards.
        unsafe {
            let inner = self.inner.as_ref();
            // NB: don't drop guard to avoid yielding access back.
            // This will prevent the value from being dropped in the shared
            // destructor and future illegal access of any kind.
            let guard = ManuallyDrop::new(inner.access.take(AccessKind::Any)?);
            // Read the pointer out without dropping the inner structure.
            // Note that the data field will after this point be invalid.
            //
            // Future access is forever prevented since we never release
            // exclusive access (see above).
            let any = ptr::read(inner.data.get());
            let expected = Hash::from_type_id(any::TypeId::of::<T>());
            let (e, any) = match any.raw_take(expected) {
                Ok(value) => return Ok(*Box::from_raw(value as *mut T)),
                Err((AnyObjError::Cast, any)) => {
                    let actual = any.type_name();
                    let e = AccessError::UnexpectedType {
                        actual,
                        expected: any::type_name::<T>().into(),
                    };
                    (e, any)
                }
                Err((e, any)) => (e.into(), any),
            };
            // At this point type coercion has failed for one reason or another,
            // so we reconstruct the state of the Shared container so that it
            // can be more cleanly dropped.
            // Drop the guard to release exclusive access.
            drop(ManuallyDrop::into_inner(guard));
            // Write the potentially modified value back so that it can be used
            // by other `Shared<T>` users pointing to the same value. This
            // conveniently also avoids dropping `any` which will be done by
            // `Shared` as appropriate.
            ptr::write(inner.data.get(), any);
            Err(e)
        }
    }
pub fn take_downcast < T > ( self ) -> Result < T , AccessError > where T : Any , { // Safety: We know that interior value is alive since this container is // alive. // // Appropriate access is checked when constructing the guards. unsafe { let inner = self . inner . as_ref ( ) ; // NB: don't drop guard to avoid yielding access back. // This will prevent the value from being dropped in the shared // destructor and future illegal access of any kind. let guard = ManuallyDrop :: new ( inner . access . take ( AccessKind :: Any ) ? ) ; // Read the pointer out without dropping the inner structure. // Note that the data field will after this point be invalid. // // Future access is forever prevented since we never release // exclusive access (see above). let any = ptr :: read ( inner . data . get ( ) ) ; let expected = Hash :: from_type_id ( any :: TypeId :: of :: < T > ( ) ) ; let ( e , any ) = match any . raw_take ( expected ) { Ok ( value ) => return Ok ( * Box :: from_raw ( value as * mut T ) ) , Err ( ( AnyObjError :: Cast , any ) ) => { let actual = any . type_name ( ) ; let e = AccessError :: UnexpectedType { actual , expected : any :: type_name :: < T > ( ) . into ( ) , } ; ( e , any ) } Err ( ( e , any ) ) => ( e . into ( ) , any ) , } ; // At this point type coercion has failed for one reason or another, // so we reconstruct the state of the Shared container so that it // can be more cleanly dropped. // Drop the guard to release exclusive access. drop ( ManuallyDrop :: into_inner ( guard ) ) ; // Write the potentially modified value back so that it can be used // by other `Shared<T>` users pointing to the same value. This // conveniently also avoids dropping `any` which will be done by // `Shared` as appropriate. ptr :: write ( inner . data . get ( ) , any ) ; Err ( e ) } }
Take the interior value, if we have exlusive access to it and there
exist no other references.
Take the interior value if we have exlusive access to it and there exist no other references .
self
self