pub fn new<U: Unsize<T>>(val: U) -> Result<StackJobOwnedInner<T, SIZE>, StackJobError<T, U>> {
        let rv = unsafe {
            let mut ptr: *const T = &val as &T;
            assert_eq!(
                ptr as *const u8, &val as *const _ as *const u8,
                "MISUSE: Closure returned different pointer"
            );
            assert_eq!(
                mem::size_of_val(&*ptr),
                mem::size_of::<U>(),
                "MISUSE: Closure returned a subset pointer"
            );

            let words = ptr_as_slice(&mut ptr);
            assert!(
                words[0] == &val as *const _ as usize,
                "BUG: Pointer layout is not (data_ptr, info...)"
            );

            // Ensure that Self is aligned same as data requires
            assert!(
                mem::align_of::<U>() <= mem::align_of::<Self>(),
                "TODO: Enforce alignment >{} (requires {})",
                mem::align_of::<Self>(),
                mem::align_of::<U>()
            );

            StackJobOwnedInner::new_raw(&words[1..], words[0] as *mut (), mem::size_of::<U>())
        };

        match rv {
            Ok(r) => {
                // Prevent the destructor from running, now that we've copied it away
                mem::forget(val);
                Ok(r)
            }
            Err((actual_size, max_size)) => Err(StackJobError {
                closure: val,
                actual_size,
                max_size,
                phantom: PhantomData,
            }),
        }
    }
/// Construct a stack-based DST
///
/// Returns Some(dst) if the allocation was successful, or None if it failed.
Construct a stack-based DST
Returns Some(dst) if the allocation was successful, or None if it failed.
Construct a stack - based DST Returns Some ( dst ) if the allocation was successful or None if it failed .
pub fn new<U: Unsize<T>>(val: U) -> Result<StackJobOwnedInner<T, SIZE>, StackJobError<T, U>> {
        let rv = unsafe {
            let mut ptr: *const T = &val as &T;
            assert_eq!(
                ptr as *const u8, &val as *const _ as *const u8,
                "MISUSE: Closure returned different pointer"
            );
            assert_eq!(
                mem::size_of_val(&*ptr),
                mem::size_of::<U>(),
                "MISUSE: Closure returned a subset pointer"
            );
            let words = ptr_as_slice(&mut ptr);
            assert!(
                words[0] == &val as *const _ as usize,
                "BUG: Pointer layout is not (data_ptr, info...)"
            );
            // Ensure that Self is aligned same as data requires
            assert!(
                mem::align_of::<U>() <= mem::align_of::<Self>(),
                "TODO: Enforce alignment >{} (requires {})",
                mem::align_of::<Self>(),
                mem::align_of::<U>()
            );
            StackJobOwnedInner::new_raw(&words[1..], words[0] as *mut (), mem::size_of::<U>())
        };
        match rv {
            Ok(r) => {
                // Prevent the destructor from running, now that we've copied it away
                mem::forget(val);
                Ok(r)
            }
            Err((actual_size, max_size)) => Err(StackJobError {
                closure: val,
                actual_size,
                max_size,
                phantom: PhantomData,
            }),
        }
    }
pub fn new < U : Unsize < T > > ( val : U ) -> Result < StackJobOwnedInner < T , SIZE > , StackJobError < T , U > > { let rv = unsafe { let mut ptr : * const T = & val as & T ; assert_eq ! ( ptr as const u8 val as const as const u8 " " ) ; assert_eq ! ( mem size_of_val ( ptr ) mem size_of U ( ) " " ) ; let words = ptr_as_slice ( & mut ptr ) ; assert ! ( words [ 0 ] val as const as usize " " ) ; // Ensure that Self is aligned same as data requires assert ! ( mem align_of U ( ) mem align_of Self ( ) " " mem align_of Self ( ) mem align_of U ( ) ) ; StackJobOwnedInner :: new_raw ( & words [ 1 .. ] , words [ 0 ] as * mut ( ) , mem :: size_of :: < U > ( ) ) } ; match rv { Ok ( r ) => { // Prevent the destructor from running, now that we've copied it away mem :: forget ( val ) ; Ok ( r ) } Err ( ( actual_size , max_size ) ) => Err ( StackJobError { closure : val , actual_size , max_size , phantom : PhantomData , } ) , } }
Construct a stack-based DST
Returns Some(dst) if the allocation was successful, or None if it failed.
Construct a stack - based DST Returns Some ( dst ) if the allocation was successful or None if it failed .
val
U
val
U