pub struct CollectionName { /* private fields */ }
Expand description
A collection name.
§Format
{root_document_name}/{collection_path}
§Examples
use firestore_path::{CollectionName,CollectionPath};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(
collection_name.to_string(),
"projects/my-project/databases/my-database/documents/chatrooms"
);
assert_eq!(
collection_name.collection_path(),
&CollectionPath::from_str("chatrooms")?
);
assert_eq!(
CollectionPath::from(collection_name),
CollectionPath::from_str("chatrooms")?
);
Implementations§
Source§impl CollectionName
impl CollectionName
Sourcepub fn new<D>(root_document_name: D, collection_path: CollectionPath) -> Selfwhere
D: Into<RootDocumentName>,
pub fn new<D>(root_document_name: D, collection_path: CollectionPath) -> Selfwhere
D: Into<RootDocumentName>,
Creates a new CollectionName
.
§Examples
use firestore_path::{CollectionName,CollectionPath,DatabaseName,RootDocumentName};
use std::str::FromStr;
let root_document_name = RootDocumentName::from_str("projects/my-project/databases/my-database/documents")?;
let collection_path = CollectionPath::from_str("chatrooms")?;
let collection_name = CollectionName::new(root_document_name, collection_path);
assert_eq!(
collection_name.to_string(),
"projects/my-project/databases/my-database/documents/chatrooms"
);
let database_name = DatabaseName::from_str("projects/my-project/databases/my-database")?;
let collection_path = CollectionPath::from_str("chatrooms")?;
let collection_name = CollectionName::new(database_name, collection_path);
assert_eq!(
collection_name.to_string(),
"projects/my-project/databases/my-database/documents/chatrooms"
);
Sourcepub fn collection_id(&self) -> &CollectionId
pub fn collection_id(&self) -> &CollectionId
Returns the CollectionId
of this CollectionName
.
§Examples
use firestore_path::{CollectionId,CollectionName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(
collection_name.collection_id(),
&CollectionId::from_str("chatrooms")?
);
Sourcepub fn collection_path(&self) -> &CollectionPath
pub fn collection_path(&self) -> &CollectionPath
Returns the CollectionPath
of this CollectionName
.
§Examples
use firestore_path::{CollectionName,CollectionPath};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(
collection_name.collection_path(),
&CollectionPath::from_str("chatrooms")?
);
Sourcepub fn database_name(&self) -> &DatabaseName
pub fn database_name(&self) -> &DatabaseName
Returns the DatabaseName
of this CollectionName
.
§Examples
use firestore_path::{DatabaseName,CollectionName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(
collection_name.database_name(),
&DatabaseName::from_str("projects/my-project/databases/my-database")?
);
Sourcepub fn doc<E, T>(&self, document_id: T) -> Result<DocumentName, Error>
pub fn doc<E, T>(&self, document_id: T) -> Result<DocumentName, Error>
Creates a new DocumentName
from this CollectionName
and document_id
.
§Examples
use firestore_path::{CollectionId,CollectionName,DocumentName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(
collection_name.doc("chatroom1")?,
DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1"
)?
);
assert_eq!(
collection_name.doc("chatroom2")?,
DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom2"
)?
);
Sourcepub fn into_doc<E, T>(self, document_id: T) -> Result<DocumentName, Error>
pub fn into_doc<E, T>(self, document_id: T) -> Result<DocumentName, Error>
Creates a new DocumentName
by consuming the CollectionName
with the provided document_id
.
§Examples
use firestore_path::{CollectionId,CollectionName,DocumentName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(
collection_name.clone().into_doc("chatroom1")?,
DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1"
)?
);
assert_eq!(
collection_name.into_doc("chatroom2")?,
DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom2"
)?
);
Sourcepub fn into_parent(self) -> Option<DocumentName>
pub fn into_parent(self) -> Option<DocumentName>
Consumes the CollectionName
, returning the parent DocumentName
.
§Examples
use firestore_path::{CollectionId,CollectionName,DocumentName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(collection_name.into_parent(), None);
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1/messages"
)?;
assert_eq!(
collection_name.clone().into_parent(),
Some(DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1"
)?)
);
assert_eq!(
collection_name.into_parent(),
Some(DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1"
)?)
);
Sourcepub fn into_root_document_name(self) -> RootDocumentName
pub fn into_root_document_name(self) -> RootDocumentName
Consumes the CollectionName
, returning the RootDocumentName
.
§Examples
use firestore_path::{CollectionName,RootDocumentName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
let root_document_name = collection_name.into_root_document_name();
assert_eq!(
root_document_name,
RootDocumentName::from_str(
"projects/my-project/databases/my-database/documents"
)?
);
Sourcepub fn parent(&self) -> Option<DocumentName>
pub fn parent(&self) -> Option<DocumentName>
Returns the parent DocumentName
of this CollectionName
.
§Examples
use firestore_path::{CollectionId,CollectionName,DocumentName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
assert_eq!(collection_name.parent(), None);
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1/messages"
)?;
assert_eq!(
collection_name.parent(),
Some(DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1"
)?)
);
assert_eq!(
collection_name.parent(),
Some(DocumentName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms/chatroom1"
)?)
);
Sourcepub fn root_document_name(&self) -> &RootDocumentName
pub fn root_document_name(&self) -> &RootDocumentName
Returns the RootDocumentName
of this CollectionName
.
§Examples
use firestore_path::{CollectionName,RootDocumentName};
use std::str::FromStr;
let collection_name = CollectionName::from_str(
"projects/my-project/databases/my-database/documents/chatrooms"
)?;
let root_document_name = collection_name.root_document_name();
assert_eq!(
root_document_name,
&RootDocumentName::from_str(
"projects/my-project/databases/my-database/documents"
)?
);
Trait Implementations§
Source§impl Clone for CollectionName
impl Clone for CollectionName
Source§fn clone(&self) -> CollectionName
fn clone(&self) -> CollectionName
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 CollectionName
impl Debug for CollectionName
Source§impl Display for CollectionName
impl Display for CollectionName
Source§impl From<CollectionName> for CollectionId
impl From<CollectionName> for CollectionId
Source§fn from(collection_name: CollectionName) -> Self
fn from(collection_name: CollectionName) -> 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<CollectionName> for DatabaseName
impl From<CollectionName> for DatabaseName
Source§fn from(collection_name: CollectionName) -> Self
fn from(collection_name: CollectionName) -> Self
Converts to this type from the input type.
Source§impl FromStr for CollectionName
impl FromStr for CollectionName
Source§impl Hash for CollectionName
impl Hash for CollectionName
Source§impl Ord for CollectionName
impl Ord for CollectionName
Source§fn cmp(&self, other: &CollectionName) -> Ordering
fn cmp(&self, other: &CollectionName) -> 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 CollectionName
impl PartialEq for CollectionName
Source§impl PartialOrd for CollectionName
impl PartialOrd for CollectionName
Source§impl TryFrom<&str> for CollectionName
impl TryFrom<&str> for CollectionName
Source§impl TryFrom<String> for CollectionName
impl TryFrom<String> for CollectionName
impl Eq for CollectionName
impl StructuralPartialEq for CollectionName
Auto Trait Implementations§
impl Freeze for CollectionName
impl RefUnwindSafe for CollectionName
impl Send for CollectionName
impl Sync for CollectionName
impl Unpin for CollectionName
impl UnwindSafe for CollectionName
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