pub fn encode_lookup_in(
    instance: *mut lcb_INSTANCE,
    request: LookupInRequest,
) -> Result<(), EncodeFailure> {
    let (id_len, id) = into_cstring(request.id);
    let cookie = Box::into_raw(Box::new(request.sender));
    let (scope_len, scope) = into_cstring(request.scope);
    let (collection_len, collection) = into_cstring(request.collection);

    let lookup_specs = request
        .specs
        .into_iter()
        .map(|spec| match spec {
            LookupInSpec::Get { path, xattr } => {
                let flags = make_subdoc_flags(None, xattr, false);
                let (path_len, path) = into_cstring(path);
                EncodedLookupSpec::Get {
                    path_len,
                    path,
                    flags,
                }
            }
            LookupInSpec::Exists { path, xattr } => {
                let flags = make_subdoc_flags(None, xattr, false);
                let (path_len, path) = into_cstring(path);
                EncodedLookupSpec::Exists {
                    path_len,
                    path,
                    flags,
                }
            }
            LookupInSpec::Count { path, xattr } => {
                let flags = make_subdoc_flags(None, xattr, false);
                let (path_len, path) = into_cstring(path);
                EncodedLookupSpec::Count {
                    path_len,
                    path,
                    flags,
                }
            }
        })
        .collect::<Vec<_>>();

    let mut command: *mut lcb_CMDSUBDOC = ptr::null_mut();
    let mut specs: *mut lcb_SUBDOCSPECS = ptr::null_mut();
    unsafe {
        verify(
            lcb_subdocspecs_create(&mut specs, lookup_specs.len()),
            cookie,
        )?;

        let mut idx = 0;
        for lookup_spec in &lookup_specs {
            match lookup_spec {
                EncodedLookupSpec::Get {
                    path_len,
                    path,
                    flags,
                } => {
                    verify(
                        lcb_subdocspecs_get(specs, idx, *flags, path.as_ptr(), *path_len),
                        cookie,
                    )?;
                }
                EncodedLookupSpec::Exists {
                    path_len,
                    path,
                    flags,
                } => {
                    verify(
                        lcb_subdocspecs_exists(specs, idx, *flags, path.as_ptr(), *path_len),
                        cookie,
                    )?;
                }
                EncodedLookupSpec::Count {
                    path_len,
                    path,
                    flags,
                } => {
                    verify(
                        lcb_subdocspecs_get_count(specs, idx, *flags, path.as_ptr(), *path_len),
                        cookie,
                    )?;
                }
            }
            idx += 1;
        }

        verify(lcb_cmdsubdoc_create(&mut command), cookie)?;
        verify(lcb_cmdsubdoc_key(command, id.as_ptr(), id_len), cookie)?;
        verify(
            lcb_cmdsubdoc_collection(
                command,
                scope.as_ptr(),
                scope_len,
                collection.as_ptr(),
                collection_len,
            ),
            cookie,
        )?;

        if let Some(timeout) = request.options.timeout {
            verify(
                lcb_cmdsubdoc_timeout(command, timeout.as_micros() as u32),
                cookie,
            )?;
        }
        if let Some(access_deleted) = request.options.access_deleted {
            verify(
                lcb_cmdsubdoc_access_deleted(command, if access_deleted { 1 } else { 0 }),
                cookie,
            )?;
        }

        verify(lcb_cmdsubdoc_specs(command, specs), cookie)?;
        verify(lcb_subdoc(instance, cookie as *mut c_void, command), cookie)?;
        verify(lcb_subdocspecs_destroy(specs), cookie)?;
        verify(lcb_cmdsubdoc_destroy(command), cookie)?;
    }

    Ok(())
}
/// Encodes a `LookupInRequest` into its libcouchbase `lcb_CMDSUBDOC` representation.
Encodes a `LookupInRequest` into its libcouchbase `lcb_CMDSUBDOC` representation.
Encodes a ` LookupInRequest ` into its libcouchbase ` lcb_CMDSUBDOC ` representation .
pub fn encode_lookup_in(
    instance: *mut lcb_INSTANCE,
    request: LookupInRequest,
) -> Result<(), EncodeFailure> {
    let (id_len, id) = into_cstring(request.id);
    let cookie = Box::into_raw(Box::new(request.sender));
    let (scope_len, scope) = into_cstring(request.scope);
    let (collection_len, collection) = into_cstring(request.collection);
    let lookup_specs = request
        .specs
        .into_iter()
        .map(|spec| match spec {
            LookupInSpec::Get { path, xattr } => {
                let flags = make_subdoc_flags(None, xattr, false);
                let (path_len, path) = into_cstring(path);
                EncodedLookupSpec::Get {
                    path_len,
                    path,
                    flags,
                }
            }
            LookupInSpec::Exists { path, xattr } => {
                let flags = make_subdoc_flags(None, xattr, false);
                let (path_len, path) = into_cstring(path);
                EncodedLookupSpec::Exists {
                    path_len,
                    path,
                    flags,
                }
            }
            LookupInSpec::Count { path, xattr } => {
                let flags = make_subdoc_flags(None, xattr, false);
                let (path_len, path) = into_cstring(path);
                EncodedLookupSpec::Count {
                    path_len,
                    path,
                    flags,
                }
            }
        })
        .collect::<Vec<_>>();
    let mut command: *mut lcb_CMDSUBDOC = ptr::null_mut();
    let mut specs: *mut lcb_SUBDOCSPECS = ptr::null_mut();
    unsafe {
        verify(
            lcb_subdocspecs_create(&mut specs, lookup_specs.len()),
            cookie,
        )?;
        let mut idx = 0;
        for lookup_spec in &lookup_specs {
            match lookup_spec {
                EncodedLookupSpec::Get {
                    path_len,
                    path,
                    flags,
                } => {
                    verify(
                        lcb_subdocspecs_get(specs, idx, *flags, path.as_ptr(), *path_len),
                        cookie,
                    )?;
                }
                EncodedLookupSpec::Exists {
                    path_len,
                    path,
                    flags,
                } => {
                    verify(
                        lcb_subdocspecs_exists(specs, idx, *flags, path.as_ptr(), *path_len),
                        cookie,
                    )?;
                }
                EncodedLookupSpec::Count {
                    path_len,
                    path,
                    flags,
                } => {
                    verify(
                        lcb_subdocspecs_get_count(specs, idx, *flags, path.as_ptr(), *path_len),
                        cookie,
                    )?;
                }
            }
            idx += 1;
        }
        verify(lcb_cmdsubdoc_create(&mut command), cookie)?;
        verify(lcb_cmdsubdoc_key(command, id.as_ptr(), id_len), cookie)?;
        verify(
            lcb_cmdsubdoc_collection(
                command,
                scope.as_ptr(),
                scope_len,
                collection.as_ptr(),
                collection_len,
            ),
            cookie,
        )?;
        if let Some(timeout) = request.options.timeout {
            verify(
                lcb_cmdsubdoc_timeout(command, timeout.as_micros() as u32),
                cookie,
            )?;
        }
        if let Some(access_deleted) = request.options.access_deleted {
            verify(
                lcb_cmdsubdoc_access_deleted(command, if access_deleted { 1 } else { 0 }),
                cookie,
            )?;
        }
        verify(lcb_cmdsubdoc_specs(command, specs), cookie)?;
        verify(lcb_subdoc(instance, cookie as *mut c_void, command), cookie)?;
        verify(lcb_subdocspecs_destroy(specs), cookie)?;
        verify(lcb_cmdsubdoc_destroy(command), cookie)?;
    }
    Ok(())
}
pub fn encode_lookup_in ( instance : * mut lcb_INSTANCE , request : LookupInRequest , ) -> Result < ( ) , EncodeFailure > { let ( id_len , id ) = into_cstring ( request . id ) ; let cookie = Box :: into_raw ( Box :: new ( request . sender ) ) ; let ( scope_len , scope ) = into_cstring ( request . scope ) ; let ( collection_len , collection ) = into_cstring ( request . collection ) ; let lookup_specs = request . specs . into_iter ( ) . map ( | spec | match spec { LookupInSpec :: Get { path , xattr } => { let flags = make_subdoc_flags ( None , xattr , false ) ; let ( path_len , path ) = into_cstring ( path ) ; EncodedLookupSpec :: Get { path_len , path , flags , } } LookupInSpec :: Exists { path , xattr } => { let flags = make_subdoc_flags ( None , xattr , false ) ; let ( path_len , path ) = into_cstring ( path ) ; EncodedLookupSpec :: Exists { path_len , path , flags , } } LookupInSpec :: Count { path , xattr } => { let flags = make_subdoc_flags ( None , xattr , false ) ; let ( path_len , path ) = into_cstring ( path ) ; EncodedLookupSpec :: Count { path_len , path , flags , } } } ) . collect :: < Vec < _ > > ( ) ; let mut command : * mut lcb_CMDSUBDOC = ptr :: null_mut ( ) ; let mut specs : * mut lcb_SUBDOCSPECS = ptr :: null_mut ( ) ; unsafe { verify ( lcb_subdocspecs_create ( & mut specs , lookup_specs . len ( ) ) , cookie , ) ? ; let mut idx = 0 ; for lookup_spec in & lookup_specs { match lookup_spec { EncodedLookupSpec :: Get { path_len , path , flags , } => { verify ( lcb_subdocspecs_get ( specs , idx , * flags , path . as_ptr ( ) , * path_len ) , cookie , ) ? ; } EncodedLookupSpec :: Exists { path_len , path , flags , } => { verify ( lcb_subdocspecs_exists ( specs , idx , * flags , path . as_ptr ( ) , * path_len ) , cookie , ) ? ; } EncodedLookupSpec :: Count { path_len , path , flags , } => { verify ( lcb_subdocspecs_get_count ( specs , idx , * flags , path . as_ptr ( ) , * path_len ) , cookie , ) ? ; } } idx += 1 ; } verify ( lcb_cmdsubdoc_create ( & mut command ) , cookie ) ? ; verify ( lcb_cmdsubdoc_key ( command , id . as_ptr ( ) , id_len ) , cookie ) ? ; verify ( lcb_cmdsubdoc_collection ( command , scope . as_ptr ( ) , scope_len , collection . as_ptr ( ) , collection_len , ) , cookie , ) ? ; if let Some ( timeout ) = request . options . timeout { verify ( lcb_cmdsubdoc_timeout ( command , timeout . as_micros ( ) as u32 ) , cookie , ) ? ; } if let Some ( access_deleted ) = request . options . access_deleted { verify ( lcb_cmdsubdoc_access_deleted ( command , if access_deleted { 1 } else { 0 } ) , cookie , ) ? ; } verify ( lcb_cmdsubdoc_specs ( command , specs ) , cookie ) ? ; verify ( lcb_subdoc ( instance , cookie as * mut c_void , command ) , cookie ) ? ; verify ( lcb_subdocspecs_destroy ( specs ) , cookie ) ? ; verify ( lcb_cmdsubdoc_destroy ( command ) , cookie ) ? ; } Ok ( ( ) ) }
Encodes a `LookupInRequest` into its libcouchbase `lcb_CMDSUBDOC` representation.
Encodes a ` LookupInRequest ` into its libcouchbase ` lcb_CMDSUBDOC ` representation .
instance
*mut lcb_INSTANCE
request
LookupInRequest
instance
*mut lcb_INSTANCE
request
LookupInRequest