pub fn encode_mutate(
    instance: *mut lcb_INSTANCE,
    request: MutateRequest,
) -> Result<(), EncodeFailure> {
    let (id_len, id) = into_cstring(request.id);
    let (value_len, value) = into_cstring(request.content);
    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 mut command: *mut lcb_CMDSTORE = ptr::null_mut();
    unsafe {
        match request.ty {
            MutateRequestType::Upsert { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_UPSERT),
                    cookie,
                )?;
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
                if let Some(expiry) = options.expiry {
                    verify(
                        lcb_cmdstore_expiry(command, expiry.as_secs() as u32),
                        cookie,
                    )?;
                }
                if options.preserve_expiry {
                    verify(lcb_cmdstore_preserve_expiry(command, 1), cookie)?;
                }
            }
            MutateRequestType::Insert { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_INSERT),
                    cookie,
                )?;
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
                if let Some(expiry) = options.expiry {
                    verify(
                        lcb_cmdstore_expiry(command, expiry.as_secs() as u32),
                        cookie,
                    )?;
                }
            }
            MutateRequestType::Replace { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_REPLACE),
                    cookie,
                )?;
                if let Some(cas) = options.cas {
                    verify(lcb_cmdstore_cas(command, cas), cookie)?;
                }
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
                if let Some(expiry) = options.expiry {
                    verify(
                        lcb_cmdstore_expiry(command, expiry.as_secs() as u32),
                        cookie,
                    )?;
                }
                if options.preserve_expiry {
                    verify(lcb_cmdstore_preserve_expiry(command, 1), cookie)?;
                }
            }
            MutateRequestType::Append { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_APPEND),
                    cookie,
                )?;
                if let Some(cas) = options.cas {
                    verify(lcb_cmdstore_cas(command, cas), cookie)?;
                }
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
            }
            MutateRequestType::Prepend { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_PREPEND),
                    cookie,
                )?;
                if let Some(cas) = options.cas {
                    verify(lcb_cmdstore_cas(command, cas), cookie)?;
                }
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
            }
        }
        verify(lcb_cmdstore_key(command, id.as_ptr(), id_len), cookie)?;
        verify(
            lcb_cmdstore_value(command, value.as_ptr(), value_len),
            cookie,
        )?;
        verify(
            lcb_cmdstore_collection(
                command,
                scope.as_ptr(),
                scope_len,
                collection.as_ptr(),
                collection_len,
            ),
            cookie,
        )?;

        verify(lcb_store(instance, cookie as *mut c_void, command), cookie)?;
        verify(lcb_cmdstore_destroy(command), cookie)?;
    }

    Ok(())
}
/// Encodes a `MutateRequest` into its libcouchbase `lcb_CMDSTORE` representation.
///
/// This method covers insert, upsert and replace since they are very similar and
/// only differ on certain properties.
Encodes a `MutateRequest` into its libcouchbase `lcb_CMDSTORE` representation.
This method covers insert, upsert and replace since they are very similar and
only differ on certain properties.
Encodes a ` MutateRequest ` into its libcouchbase ` lcb_CMDSTORE ` representation . This method covers insert upsert and replace since they are very similar and only differ on certain properties .
pub fn encode_mutate(
    instance: *mut lcb_INSTANCE,
    request: MutateRequest,
) -> Result<(), EncodeFailure> {
    let (id_len, id) = into_cstring(request.id);
    let (value_len, value) = into_cstring(request.content);
    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 mut command: *mut lcb_CMDSTORE = ptr::null_mut();
    unsafe {
        match request.ty {
            MutateRequestType::Upsert { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_UPSERT),
                    cookie,
                )?;
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
                if let Some(expiry) = options.expiry {
                    verify(
                        lcb_cmdstore_expiry(command, expiry.as_secs() as u32),
                        cookie,
                    )?;
                }
                if options.preserve_expiry {
                    verify(lcb_cmdstore_preserve_expiry(command, 1), cookie)?;
                }
            }
            MutateRequestType::Insert { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_INSERT),
                    cookie,
                )?;
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
                if let Some(expiry) = options.expiry {
                    verify(
                        lcb_cmdstore_expiry(command, expiry.as_secs() as u32),
                        cookie,
                    )?;
                }
            }
            MutateRequestType::Replace { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_REPLACE),
                    cookie,
                )?;
                if let Some(cas) = options.cas {
                    verify(lcb_cmdstore_cas(command, cas), cookie)?;
                }
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
                if let Some(expiry) = options.expiry {
                    verify(
                        lcb_cmdstore_expiry(command, expiry.as_secs() as u32),
                        cookie,
                    )?;
                }
                if options.preserve_expiry {
                    verify(lcb_cmdstore_preserve_expiry(command, 1), cookie)?;
                }
            }
            MutateRequestType::Append { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_APPEND),
                    cookie,
                )?;
                if let Some(cas) = options.cas {
                    verify(lcb_cmdstore_cas(command, cas), cookie)?;
                }
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
            }
            MutateRequestType::Prepend { options } => {
                verify(
                    lcb_cmdstore_create(&mut command, lcb_STORE_OPERATION_LCB_STORE_PREPEND),
                    cookie,
                )?;
                if let Some(cas) = options.cas {
                    verify(lcb_cmdstore_cas(command, cas), cookie)?;
                }
                if let Some(timeout) = options.timeout {
                    verify(
                        lcb_cmdstore_timeout(command, timeout.as_micros() as u32),
                        cookie,
                    )?;
                }
            }
        }
        verify(lcb_cmdstore_key(command, id.as_ptr(), id_len), cookie)?;
        verify(
            lcb_cmdstore_value(command, value.as_ptr(), value_len),
            cookie,
        )?;
        verify(
            lcb_cmdstore_collection(
                command,
                scope.as_ptr(),
                scope_len,
                collection.as_ptr(),
                collection_len,
            ),
            cookie,
        )?;
        verify(lcb_store(instance, cookie as *mut c_void, command), cookie)?;
        verify(lcb_cmdstore_destroy(command), cookie)?;
    }
    Ok(())
}
pub fn encode_mutate ( instance : * mut lcb_INSTANCE , request : MutateRequest , ) -> Result < ( ) , EncodeFailure > { let ( id_len , id ) = into_cstring ( request . id ) ; let ( value_len , value ) = into_cstring ( request . content ) ; 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 mut command : * mut lcb_CMDSTORE = ptr :: null_mut ( ) ; unsafe { match request . ty { MutateRequestType :: Upsert { options } => { verify ( lcb_cmdstore_create ( & mut command , lcb_STORE_OPERATION_LCB_STORE_UPSERT ) , cookie , ) ? ; if let Some ( timeout ) = options . timeout { verify ( lcb_cmdstore_timeout ( command , timeout . as_micros ( ) as u32 ) , cookie , ) ? ; } if let Some ( expiry ) = options . expiry { verify ( lcb_cmdstore_expiry ( command , expiry . as_secs ( ) as u32 ) , cookie , ) ? ; } if options . preserve_expiry { verify ( lcb_cmdstore_preserve_expiry ( command , 1 ) , cookie ) ? ; } } MutateRequestType :: Insert { options } => { verify ( lcb_cmdstore_create ( & mut command , lcb_STORE_OPERATION_LCB_STORE_INSERT ) , cookie , ) ? ; if let Some ( timeout ) = options . timeout { verify ( lcb_cmdstore_timeout ( command , timeout . as_micros ( ) as u32 ) , cookie , ) ? ; } if let Some ( expiry ) = options . expiry { verify ( lcb_cmdstore_expiry ( command , expiry . as_secs ( ) as u32 ) , cookie , ) ? ; } } MutateRequestType :: Replace { options } => { verify ( lcb_cmdstore_create ( & mut command , lcb_STORE_OPERATION_LCB_STORE_REPLACE ) , cookie , ) ? ; if let Some ( cas ) = options . cas { verify ( lcb_cmdstore_cas ( command , cas ) , cookie ) ? ; } if let Some ( timeout ) = options . timeout { verify ( lcb_cmdstore_timeout ( command , timeout . as_micros ( ) as u32 ) , cookie , ) ? ; } if let Some ( expiry ) = options . expiry { verify ( lcb_cmdstore_expiry ( command , expiry . as_secs ( ) as u32 ) , cookie , ) ? ; } if options . preserve_expiry { verify ( lcb_cmdstore_preserve_expiry ( command , 1 ) , cookie ) ? ; } } MutateRequestType :: Append { options } => { verify ( lcb_cmdstore_create ( & mut command , lcb_STORE_OPERATION_LCB_STORE_APPEND ) , cookie , ) ? ; if let Some ( cas ) = options . cas { verify ( lcb_cmdstore_cas ( command , cas ) , cookie ) ? ; } if let Some ( timeout ) = options . timeout { verify ( lcb_cmdstore_timeout ( command , timeout . as_micros ( ) as u32 ) , cookie , ) ? ; } } MutateRequestType :: Prepend { options } => { verify ( lcb_cmdstore_create ( & mut command , lcb_STORE_OPERATION_LCB_STORE_PREPEND ) , cookie , ) ? ; if let Some ( cas ) = options . cas { verify ( lcb_cmdstore_cas ( command , cas ) , cookie ) ? ; } if let Some ( timeout ) = options . timeout { verify ( lcb_cmdstore_timeout ( command , timeout . as_micros ( ) as u32 ) , cookie , ) ? ; } } } verify ( lcb_cmdstore_key ( command , id . as_ptr ( ) , id_len ) , cookie ) ? ; verify ( lcb_cmdstore_value ( command , value . as_ptr ( ) , value_len ) , cookie , ) ? ; verify ( lcb_cmdstore_collection ( command , scope . as_ptr ( ) , scope_len , collection . as_ptr ( ) , collection_len , ) , cookie , ) ? ; verify ( lcb_store ( instance , cookie as * mut c_void , command ) , cookie ) ? ; verify ( lcb_cmdstore_destroy ( command ) , cookie ) ? ; } Ok ( ( ) ) }
Encodes a `MutateRequest` into its libcouchbase `lcb_CMDSTORE` representation.
Encodes a ` MutateRequest ` into its libcouchbase ` lcb_CMDSTORE ` representation .
instance
*mut lcb_INSTANCE
request
MutateRequest
instance
*mut lcb_INSTANCE
request
MutateRequest