Skip to content

Commit

Permalink
doc: add doc for builders
Browse files Browse the repository at this point in the history
  • Loading branch information
fMeow committed Aug 17, 2020
1 parent a8e592d commit 8875b5a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/custom_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ impl ClientExt for ReqwestClient {
}
}

// This cfg is only to make rust compiler happy in Github Action, you can just ignore it
// This cfg is only to make rust compiler happy in Github Action, you can just
// ignore it
#[cfg(feature = "reqwest_async")]
#[tokio::main]
async fn main() -> Result<(), Error> {
Expand Down
15 changes: 15 additions & 0 deletions src/aql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ use serde_json::value::Value;
use typed_builder::TypedBuilder;

#[derive(Debug, Serialize, TypedBuilder)]
#[builder(
doc,
builder_method_doc = r#"Create a builder for building `AqlQuery`.
On the builder, call `.query(...)`, `.bind_vars(...)(optional)`, `.bind_var(...)(optional)`,
`.try_bind(...)(optional)`, `.count(...)(optional)`, `.batch_size(...)(optional)`,
`.cache(...)(optional)`, `.memory_limit(...)(optional)`, `.ttl(...)(optional)`,
`.options(...)(optional)` to set the values of the fields (they accept Into values).
Use `.try_bind(...)` to accept any serializable struct
while `.bind_value(...)` accepts an `Into<serde_json::Value>`.
Finally, call .build() to create the instance of AqlQuery."#
)]
#[serde(rename_all = "camelCase")]
pub struct AqlQuery<'a> {
/// query string to be executed
Expand Down Expand Up @@ -238,6 +252,7 @@ impl<'a, __query, __count, __batch_size, __cache, __memory_limit, __ttl, __optio
}

#[derive(Debug, Serialize, TypedBuilder, PartialEq)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct AqlOptions {
/// When set to true, the query will throw an exception and abort instead of
Expand Down
5 changes: 5 additions & 0 deletions src/collection/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::collection::CollectionType;

/// Options for create a collection
#[derive(Serialize, PartialEq, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct CreateParameters {
/// Default is 1 which means the server will only report success back to the
Expand Down Expand Up @@ -41,6 +42,7 @@ where
}
/// Options for create a collection
#[derive(Serialize, PartialEq, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct CreateOptions<'a> {
name: &'a str,
Expand Down Expand Up @@ -222,6 +224,7 @@ fn is_true(x: &bool) -> bool {
}

#[derive(Debug, Deserialize, Serialize, TypedBuilder, PartialEq)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct KeyOptions {
/// if set to true, then it is allowed to supply own key values in the _key
Expand Down Expand Up @@ -263,6 +266,7 @@ impl Default for KeyOptions {

/// Options for checksum
#[derive(Serialize, Deserialize, PartialEq, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct ChecksumOptions {
/// By setting the optional query parameter withRevisions to true, then
Expand All @@ -289,6 +293,7 @@ impl Default for ChecksumOptions {
}

#[derive(Debug, Deserialize, Serialize, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct PropertiesOptions {
/// If true then creating or changing a document will wait until the data
Expand Down
4 changes: 4 additions & 0 deletions src/document/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use typed_builder::TypedBuilder;

/// Options for document insertion.
#[derive(Serialize, Deserialize, PartialEq, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct InsertOptions {
/// Wait until document has been synced to disk.
Expand Down Expand Up @@ -48,6 +49,7 @@ impl Default for InsertOptions {

/// Options for document update,
#[derive(Serialize, Deserialize, PartialEq, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct UpdateOptions {
/// If the intention is to delete existing attributes with the patch
Expand Down Expand Up @@ -142,6 +144,7 @@ pub enum OverwriteMode {

/// Options for document replace,
#[derive(Serialize, Deserialize, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct ReplaceOptions {
/// Wait until document has been synced to disk.
Expand Down Expand Up @@ -202,6 +205,7 @@ impl Default for ReadOptions {

/// Options for document removes,
#[derive(Serialize, Deserialize, TypedBuilder)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct RemoveOptions {
/// Wait until document has been synced to disk.
Expand Down
5 changes: 3 additions & 2 deletions tests/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ async fn test_put_rotate_journal() {

let rotate = coll.rotate_journal().await;

// TODO got error in arangoDB 3.7.1: expecting one of the actions 'load', 'unload',
// 'truncate', 'properties', 'compact', 'rename', 'loadIndexesIntoMemory'
// TODO got error in arangoDB 3.7.1: expecting one of the actions 'load',
// 'unload', 'truncate', 'properties', 'compact', 'rename',
// 'loadIndexesIntoMemory'

// assert_eq!(rotate.is_err(), true, "succeed rotating journal");
// if let ClientError::Arango(error) = rotate.unwrap_err() {
Expand Down

0 comments on commit 8875b5a

Please sign in to comment.