mibes / couch-rs

CouchDB library for Rust
Apache License 2.0
59 stars 17 forks source link

Borrow documents instead of consuming them #7

Closed horacimacias closed 3 years ago

horacimacias commented 3 years ago

This PR uses a &mut of a document instead of taking full ownership of the document passed. Main reason for this is to be able to do something like:

                    // create the document
                    match db.create(&mut doc).await {
                        Ok(r) => println!("Document was created with ID: {} and Rev: {}", r.id, r.rev),
                        Err(err) => println!("error creating document {}: {:?}", doc, err),
                    }

so the document passed can still be referred to after executing an operation, otherwise only the Ok branch provides the document and the Err branch does not (so it's not possible to log the document for example, on error situations, without previously cloning the document which would be done before knowing if operation will succeed or not)

Also the operations taking a single document and operations taking multiple documents (e.g. bulk_docs) now have a closer signature (DocumentCreatedResult and Vec)

horacimacias commented 3 years ago

This PR does have some small but breaking changes to the API (using reference instead of owned struct) but I believe the changes resulting from it are still worth the update.

mibes commented 3 years ago

Merged the PR into develop. Thanks!