Module couchdb::path [] [src]

The path module provides types for identifying databases, documents, etc.

Summary

  • The path module provides a suite of types for names, ids, and paths—all of which are used to specify the location of CouchDB resources, such as databases, documents, and views.

  • Both names and ids are percent-decoded, but whereas a name comprises exactly one path segment, an id may comprise more.

  • Both names and ids are useful for constructing query parameters, headers, and capturing CouchDB response data.

  • A path is a full percent-encoded URL path and is most useful when constructing a URL for an HTTP request. It implements neither Serialize nor Deserialize.

Remarks

The CouchDB API uses strings for specifying the locations of resources, and using these strings “in the raw” can be error-prone. The path module provides safer alternatives by way of stronger types.

There are two chief kinds of errors that stronger types help eliminate:

  • Incorrect percent-encoding. For example, document names and attachment names may contain slashes (/) and other non-standard characters, and neglect to percent-encode these characters can cause obscure bugs.

  • Type mismatches. For example, mistakenly using a database path to delete a document could cause massive data loss.

Note, however, that the path module merely makes these types available. It is up to the application programmer to make use of them.

Example

extern crate couchdb;

// Construct view path: '/alpha/_design/bravo/_view/charlie delta':

let view_path = couchdb::DatabaseName::new("alpha")
    .with_design_document_id(couchdb::DesignDocumentName::new("bravo"))
    .with_view_name("charlie delta");

// Paths are percent-encoded and thus well suited for building URLs.

let s = view_path.to_string();
assert_eq!(s, "/alpha/_design/bravo/_view/charlie%20delta");

// Alternatively, paths can be parsed from string.

let v2 = couchdb::ViewPath::parse(&s).unwrap();
assert_eq!(view_path, v2);

Structs

AttachmentName

AttachmentName is a single URL path segment that specifies the name of an attachment.

AttachmentPath

AttachmentPath is the full URL path of an attachment.

DatabaseName

DatabaseName is a single URL path segment that specifies the name of a database.

DatabasePath

DatabasePath is the full URL path of a database.

DesignDocumentId

DesignDocumentId comprises URL path segments that, together, identify a design document.

DesignDocumentName

DesignDocumentName is a single URL path segment that specifies the name of a design document.

DesignDocumentPath

DesignDocumentPath is the full URL path of a design document.

DocumentId

DocumentId comprises one or more URL path segments that, together, identify a document.

DocumentPath

DocumentPath is the full URL path of a document.

LocalDocumentName

LocalDocumentName is a single URL path segment that specifies the name of a local document.

NormalDocumentName

NormalDocumentName is a single URL path segment that specifies the name of a document that is neither a design document nor a local document.

ViewId

ViewId comprises URL path segments that combine a design document name and a view name.

ViewName

ViewName is a single URL path segment that specifies the name of a view.

ViewPath

ViewPath is the full URL path of a view.