pub struct CollectionPath { /* private fields */ }
Expand description
A collection path.
§Format
{collection_id}
{document_path}/{collection_id}
§Examples
use firestore_path::CollectionPath;
use std::str::FromStr;
let collection_path = CollectionPath::from_str("chatrooms")?;
assert_eq!(collection_path.to_string(), "chatrooms");
let collection_path = CollectionPath::from_str("chatrooms/chatroom1/messages")?;
assert_eq!(collection_path.to_string(), "chatrooms/chatroom1/messages");
Implementations§
Source§impl CollectionPath
impl CollectionPath
Sourcepub fn new(parent: Option<DocumentPath>, collection_id: CollectionId) -> Self
pub fn new(parent: Option<DocumentPath>, collection_id: CollectionId) -> Self
Create a new CollectionPath
.
§Examples
use firestore_path::{CollectionId,CollectionPath,DocumentPath};
use std::str::FromStr;
let collection_id = CollectionId::from_str("chatrooms")?;
let collection_path = CollectionPath::new(None, collection_id);
assert_eq!(collection_path.to_string(), "chatrooms");
let document_path = DocumentPath::from_str("chatrooms/chatroom1")?;
let collection_id = CollectionId::from_str("messages")?;
let collection_path = CollectionPath::new(Some(document_path), collection_id);
assert_eq!(collection_path.to_string(), "chatrooms/chatroom1/messages");
Sourcepub fn collection_id(&self) -> &CollectionId
pub fn collection_id(&self) -> &CollectionId
Returns the CollectionId
of this CollectionPath
.
§Examples
use firestore_path::{CollectionId,CollectionPath,DocumentPath};
use std::str::FromStr;
let collection_path = CollectionPath::from_str("chatrooms")?;
assert_eq!(collection_path.collection_id(), &CollectionId::from_str("chatrooms")?);
Sourcepub fn doc<E, T>(&self, document_id: T) -> Result<DocumentPath, Error>
pub fn doc<E, T>(&self, document_id: T) -> Result<DocumentPath, Error>
Create a new DocumentPath
from this CollectionPath
and document_id
.
§Examples
use firestore_path::{CollectionPath,DocumentPath};
use std::str::FromStr;
let collection_path = CollectionPath::from_str("chatrooms")?;
assert_eq!(
collection_path.doc("chatroom1")?,
DocumentPath::from_str("chatrooms/chatroom1")?
);
assert_eq!(
collection_path.doc("chatroom2")?,
DocumentPath::from_str("chatrooms/chatroom2")?
);
Sourcepub fn into_doc<E, T>(self, document_id: T) -> Result<DocumentPath, Error>
pub fn into_doc<E, T>(self, document_id: T) -> Result<DocumentPath, Error>
Create a new DocumentPath
by consuming the CollectionPath
with the provided document_id
.
§Examples
use firestore_path::{CollectionPath,DocumentPath};
use std::str::FromStr;
let collection_path = CollectionPath::from_str("chatrooms")?;
assert_eq!(
collection_path.clone().into_doc("chatroom1")?,
DocumentPath::from_str("chatrooms/chatroom1")?
);
assert_eq!(
collection_path.into_doc("chatroom2")?,
DocumentPath::from_str("chatrooms/chatroom2")?
);
Sourcepub fn into_parent(self) -> Option<DocumentPath>
pub fn into_parent(self) -> Option<DocumentPath>
Consumes the CollectionPath
, returning the parent DocumentPath
.
§Examples
use firestore_path::{CollectionPath,DocumentPath};
use std::str::FromStr;
let collection_path = CollectionPath::from_str("chatrooms")?;
assert_eq!(collection_path.into_parent(), None);
let collection_path = CollectionPath::from_str("chatrooms/chatroom1/messages")?;
assert_eq!(collection_path.clone().into_parent(), Some(DocumentPath::from_str("chatrooms/chatroom1")?));
assert_eq!(collection_path.into_parent(), Some(DocumentPath::from_str("chatrooms/chatroom1")?));
Sourcepub fn parent(&self) -> Option<&DocumentPath>
pub fn parent(&self) -> Option<&DocumentPath>
Returns the parent DocumentPath
of this CollectionPath
.
§Examples
use firestore_path::{CollectionPath,DocumentPath};
use std::str::FromStr;
let collection_path = CollectionPath::from_str("chatrooms")?;
assert_eq!(collection_path.parent(), None);
let collection_path = CollectionPath::from_str("chatrooms/chatroom1/messages")?;
assert_eq!(collection_path.parent(), Some(&DocumentPath::from_str("chatrooms/chatroom1")?));
Trait Implementations§
Source§impl Clone for CollectionPath
impl Clone for CollectionPath
Source§fn clone(&self) -> CollectionPath
fn clone(&self) -> CollectionPath
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CollectionPath
impl Debug for CollectionPath
Source§impl Display for CollectionPath
impl Display for CollectionPath
Source§impl From<CollectionId> for CollectionPath
impl From<CollectionId> for CollectionPath
Source§fn from(collection_id: CollectionId) -> Self
fn from(collection_id: CollectionId) -> Self
Converts to this type from the input type.
Source§impl From<CollectionName> for CollectionPath
impl From<CollectionName> for CollectionPath
Source§fn from(collection_name: CollectionName) -> Self
fn from(collection_name: CollectionName) -> Self
Converts to this type from the input type.
Source§impl From<CollectionPath> for CollectionId
impl From<CollectionPath> for CollectionId
Source§fn from(collection_path: CollectionPath) -> Self
fn from(collection_path: CollectionPath) -> Self
Converts to this type from the input type.
Source§impl From<CollectionPath> for Option<DocumentPath>
impl From<CollectionPath> for Option<DocumentPath>
Source§fn from(collection_path: CollectionPath) -> Self
fn from(collection_path: CollectionPath) -> Self
Converts to this type from the input type.
Source§impl From<DocumentPath> for CollectionPath
impl From<DocumentPath> for CollectionPath
Source§fn from(document_path: DocumentPath) -> Self
fn from(document_path: DocumentPath) -> Self
Converts to this type from the input type.
Source§impl FromStr for CollectionPath
impl FromStr for CollectionPath
Source§impl Hash for CollectionPath
impl Hash for CollectionPath
Source§impl Ord for CollectionPath
impl Ord for CollectionPath
Source§fn cmp(&self, other: &CollectionPath) -> Ordering
fn cmp(&self, other: &CollectionPath) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for CollectionPath
impl PartialEq for CollectionPath
Source§impl PartialOrd for CollectionPath
impl PartialOrd for CollectionPath
Source§impl TryFrom<&str> for CollectionPath
impl TryFrom<&str> for CollectionPath
Source§impl TryFrom<String> for CollectionPath
impl TryFrom<String> for CollectionPath
impl Eq for CollectionPath
impl StructuralPartialEq for CollectionPath
Auto Trait Implementations§
impl Freeze for CollectionPath
impl RefUnwindSafe for CollectionPath
impl Send for CollectionPath
impl Sync for CollectionPath
impl Unpin for CollectionPath
impl UnwindSafe for CollectionPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more