From 3b0bae8cb92237494be03b5ff19812fe3b4ffa42 Mon Sep 17 00:00:00 2001 From: bouzuya Date: Wed, 20 Dec 2023 20:10:26 +0900 Subject: [PATCH] Add impl From for CollectionPath --- src/collection_path.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/collection_path.rs b/src/collection_path.rs index a6d3f7e..4e941d7 100644 --- a/src/collection_path.rs +++ b/src/collection_path.rs @@ -124,6 +124,12 @@ impl CollectionPath { } } +impl std::convert::From for CollectionPath { + fn from(collection_id: CollectionId) -> Self { + CollectionPath::new(None, collection_id) + } +} + impl std::convert::From for CollectionId { fn from(collection_path: CollectionPath) -> Self { collection_path.collection_id @@ -246,6 +252,16 @@ mod tests { Ok(()) } + #[test] + fn test_impl_from_collection_id_for_collection_path() -> anyhow::Result<()> { + let collection_id = CollectionId::from_str("chatrooms")?; + assert_eq!( + CollectionPath::from(collection_id), + CollectionPath::from_str("chatrooms")? + ); + Ok(()) + } + #[test] fn test_impl_from_collection_path_for_collection_id() -> anyhow::Result<()> { let collection_path = CollectionPath::from_str("chatrooms")?;