昨日は bouzuya/firestore-path 0.1.0 をつくった。今日は 0.2.0 をつくった。
firestore-path は Rust で Firestore のドキュメントやコレクションのパスを扱うための crate 。次のような型を提供することでパスを表す文字列を扱いやすくする。
CollectionId
CollectionName
CollectionPath
DatabaseId
DatabaseName
DocumentId
DocumentName
DocumentPath
ProjectId
使用例。
use firestore_path::{CollectionId, CollectionName, DatabaseId, DatabaseName, DocumentId, DocumentName, ProjectId}; use std::str::FromStr; fn main() -> anyhow::Result<()> { let project_id = ProjectId::from_str("my-project")?; let database_id = DatabaseId::from_str("my-database")?; let database_name = DatabaseName::new(project_id, database_id); let document_name: DocumentName = database_name .collection("chatrooms")? .doc("chatroom1")? .collection("messages")? .doc("message1")?; assert_eq!( document_name.to_string(), "projects/my-project/databases/my-database/documents/chatrooms/chatroom1/messages/message1" ); assert_eq!(document_name.document_id().as_ref(), "message1"); let collection_name: CollectionName = document_name.parent(); assert_eq!( collection_name.to_string(), "projects/my-project/databases/my-database/documents/chatrooms/chatroom1/messages" ); assert_eq!(collection_name.collection_id().as_ref(), "messages"); Ok(()) }
今日は database_name
というメソッドを追加して 0.2.0 にした。
エラーハンドリングを改善して 0.3.0 にしようと考えている。
今日のコミット。