/// Helper function to fetch a reference to the `Rc` from the OCaml representation
/// of a custom block.
Helper function to fetch a reference to the `Rc` from the OCaml representation
of a custom block.
Helper function to fetch a reference to the ` Rc ` from the OCaml representation of a custom block .
fn rc_from_value<'a, T: CamlSerialize>(value: Value<'a>) -> Result<&'a Rc<T>, FromError> {
    let block = from::expect_block(value)?;
    from::expect_block_tag(block, CUSTOM_TAG)?;
    from::expect_block_size(block, CUSTOM_BLOCK_SIZE_IN_WORDS)?;
    // We still don't know whether this block is in fact a
    // CustomBlockOcamlRep<T>--it may be a CustomBlockOcamlRep<U>, or some
    // other custom block which happens to be the same size. We can verify
    // that the block is actually a CustomBlockOcamlRep<T> by checking that
    // it points to the correct CustomOperations struct.
    let ops = <T as CamlSerialize>::operations();
    if !std::ptr::eq(ops, block[0].to_bits() as *const CustomOperations) {
        return Err(FromError::UnexpectedCustomOps {
            expected: ops as *const _ as usize,
            actual: block[0].to_bits(),
        });
    }
    let value_ptr = value.to_bits() as *const CustomBlockOcamlRep<T>;
    // Safety: `value_ptr` is guaranteed to be aligned to
    // `align_of::<Value>()`, and our use of `expect_block_size` guarantees
    // that the pointer is valid for reads of `CUSTOM_BLOCK_SIZE_IN_WORDS *
    // `size_of::<Value>()` bytes. Since the first field points to the right
    // operations struct, we either have a valid `CustomBlockOCamlRep<T>`
    // (i.e., constructed above in our `ToOcamlRep` implementation) or
    // someone went out of their way to construct an invalid one. Assume
    // it's valid and read in the `CustomBlockOcamlRep<T>`.
    let custom_block = unsafe { value_ptr.as_ref().unwrap() };
    Ok(&custom_block.1)
}
fn rc_from_value < ' a , T : CamlSerialize > ( value : Value < ' a > ) -> Result < & ' a Rc < T > , FromError > { let block = from :: expect_block ( value ) ? ; from :: expect_block_tag ( block , CUSTOM_TAG ) ? ; from :: expect_block_size ( block , CUSTOM_BLOCK_SIZE_IN_WORDS ) ? ; // We still don't know whether this block is in fact a // CustomBlockOcamlRep<T>--it may be a CustomBlockOcamlRep<U>, or some // other custom block which happens to be the same size. We can verify // that the block is actually a CustomBlockOcamlRep<T> by checking that // it points to the correct CustomOperations struct. let ops = < T as CamlSerialize > :: operations ( ) ; if ! std :: ptr :: eq ( ops , block [ 0 ] . to_bits ( ) as * const CustomOperations ) { return Err ( FromError :: UnexpectedCustomOps { expected : ops as * const _ as usize , actual : block [ 0 ] . to_bits ( ) , } ) ; } let value_ptr = value . to_bits ( ) as * const CustomBlockOcamlRep < T > ; // Safety: `value_ptr` is guaranteed to be aligned to // `align_of::<Value>()`, and our use of `expect_block_size` guarantees // that the pointer is valid for reads of `CUSTOM_BLOCK_SIZE_IN_WORDS * // `size_of::<Value>()` bytes. Since the first field points to the right // operations struct, we either have a valid `CustomBlockOCamlRep<T>` // (i.e., constructed above in our `ToOcamlRep` implementation) or // someone went out of their way to construct an invalid one. Assume // it's valid and read in the `CustomBlockOcamlRep<T>`. let custom_block = unsafe { value_ptr . as_ref ( ) . unwrap ( ) } ; Ok ( & custom_block . 1 ) }
Helper function to fetch a reference to the `Rc` from the OCaml representation
of a custom block.
Helper function to fetch a reference to the ` Rc ` from the OCaml representation of a custom block .
value
Value<'a>