firestore_path/lib.rs
1//! A Firestore path helper.
2//!
3//! ```rust
4//! # fn main() -> anyhow::Result<()> {
5//! use firestore_path::{CollectionId, CollectionName, CollectionPath, DatabaseId, DatabaseName, DocumentId, DocumentName, DocumentPath, ProjectId, RootDocumentName};
6//! use std::str::FromStr;
7//!
8//! let project_id = ProjectId::from_str("my-project")?;
9//! let database_id = DatabaseId::from_str("my-database")?;
10//! let database_name = DatabaseName::new(project_id, database_id);
11//! assert_eq!(database_name.to_string(), "projects/my-project/databases/my-database");
12//! assert_eq!(
13//! DatabaseName::from_project_id("my-project")?.to_string(),
14//! "projects/my-project/databases/(default)"
15//! );
16//!
17//! let root_document_name: RootDocumentName = database_name.root_document_name();
18//! assert_eq!(root_document_name.to_string(), "projects/my-project/databases/my-database/documents");
19//!
20//! let collection_name: CollectionName = root_document_name.collection("chatrooms")?;
21//! assert_eq!(collection_name.to_string(), "projects/my-project/databases/my-database/documents/chatrooms");
22//! assert_eq!(collection_name.collection_id().as_ref(), "chatrooms");
23//!
24//! let document_name: DocumentName = collection_name.doc("chatroom1")?;
25//! assert_eq!(document_name.to_string(), "projects/my-project/databases/my-database/documents/chatrooms/chatroom1");
26//! assert_eq!(document_name.collection_id().as_ref(), "chatrooms");
27//! assert_eq!(document_name.document_id().as_ref(), "chatroom1");
28//!
29//! let collection_id = CollectionId::from_str("messages")?;
30//! let collection_path = CollectionPath::from(collection_id);
31//! assert_eq!(collection_path.to_string(), "messages");
32//!
33//! let document_id = DocumentId::from_str("message1")?;
34//! let document_path: DocumentPath = collection_path.doc(document_id)?;
35//! assert_eq!(document_path.to_string(), "messages/message1");
36//!
37//! let child_document_name = document_name.doc(document_path)?;
38//! assert_eq!(
39//! child_document_name.to_string(),
40//! "projects/my-project/databases/my-database/documents/chatrooms/chatroom1/messages/message1"
41//! );
42//! # Ok(())
43//! # }
44//! ```
45mod collection_id;
46mod collection_name;
47mod collection_path;
48mod database_id;
49mod database_name;
50mod document_id;
51mod document_name;
52mod document_path;
53mod error;
54mod project_id;
55mod root_document_name;
56
57pub use self::collection_id::CollectionId;
58pub use self::collection_name::CollectionName;
59pub use self::collection_path::CollectionPath;
60pub use self::database_id::DatabaseId;
61pub use self::database_name::DatabaseName;
62pub use self::document_id::DocumentId;
63pub use self::document_name::DocumentName;
64pub use self::document_path::DocumentPath;
65pub use self::error::Error;
66pub use self::project_id::ProjectId;
67pub use self::root_document_name::RootDocumentName;