pub struct FirestoreCollectionId(/* private fields */);Expand description
A Firestore collection ID that has been checked against Firestore’s ID rules.
Construct one with FirestoreCollectionId::new at the point a collection name enters your
system — the natural case is a collection chosen at runtime, where an unchecked / would
silently re-target the operation at a different collection. It has the same API shape, and the
same design rationale (no consuming unwrap, no reserved-namespace check, the String escape
hatch), as FirestoreDocumentId; see that type’s docs for the full explanation.
use firestore::FirestoreCollectionId;
let id = FirestoreCollectionId::new("users").expect("valid collection id");
assert_eq!(id.as_str(), "users");
let err = FirestoreCollectionId::new("a/b").unwrap_err();
assert!(err.to_string().contains("collection_id"));
assert!(err.to_string().contains(".parent("));
let err = FirestoreCollectionId::new("").unwrap_err();
assert!(err.to_string().contains("collection_id"));Drop-in by reference into the fluent API, exactly like FirestoreDocumentId:
use firestore::{FirestoreCollectionId, FirestoreDb, FirestoreResult};
let db = FirestoreDb::new("my-project").await?;
let collection = FirestoreCollectionId::new("users")?;
let documents = db.fluent().list().from(&collection).stream_all().await?;Stored in a caller’s own struct:
use firestore::FirestoreCollectionId;
struct DynamicCollectionRequest {
collection: FirestoreCollectionId,
}
let request = DynamicCollectionRequest {
collection: FirestoreCollectionId::new("users")?,
};
assert_eq!(request.collection.as_str(), "users");Implementations§
Source§impl FirestoreCollectionId
impl FirestoreCollectionId
Sourcepub fn new<S: Into<String>>(id: S) -> FirestoreResult<Self>
pub fn new<S: Into<String>>(id: S) -> FirestoreResult<Self>
Validates id and wraps it.
§Errors
Returns FirestoreError::InvalidParametersError if id is empty, longer than 1500
bytes, contains /, or is exactly "." or "..".
Sourcepub fn validate_str(id: &str) -> FirestoreResult<()>
pub fn validate_str(id: &str) -> FirestoreResult<()>
Validates id without allocating or constructing a value.
§Errors
Same conditions as FirestoreCollectionId::new.
Sourcepub fn validate(&self) -> FirestoreResult<()>
pub fn validate(&self) -> FirestoreResult<()>
Re-validates an already-constructed ID.
A valid FirestoreCollectionId cannot become invalid after construction, so this always
succeeds; it exists to mirror FirestoreListenerTarget::validate
for callers that validate every ID-like value the same way.
§Errors
Never fails; returns FirestoreResult<()> for symmetry with FirestoreCollectionId::validate_str.
Sourcepub const fn from_static(id: &'static str) -> Self
pub const fn from_static(id: &'static str) -> Self
Validates id at compile time and wraps it without allocating, for a name known up front.
Declare validated names the way you would declare const NAME: &str = "..." today:
use firestore::FirestoreCollectionId;
const USERS: FirestoreCollectionId = FirestoreCollectionId::from_static("users");
assert_eq!(USERS.as_str(), "users");Used in a const or static item, an invalid literal is a compile error: evaluating the
item panics, which rustc reports at the definition site rather than letting the invalid
value reach a binary. Called from inside a function body, where the result is only a
runtime value, the same invalid literal panics instead, exactly like an out-of-bounds
const fn array index would.
use firestore::FirestoreCollectionId;
const BAD: FirestoreCollectionId = FirestoreCollectionId::from_static("a/b");§Panics
Panics if id is empty, longer than 1500 bytes, contains /, or is exactly "." or
"..", and the call is not evaluated at compile time.
Sourcepub fn value(&self) -> &str
pub fn value(&self) -> &str
Returns the wrapped ID.
Equivalent to as_str; kept as a separate method so a validated ID reads
the same as rvstruct::ValueStruct::value elsewhere in this crate’s API. There is no
consuming equivalent that returns an owned String (see the FirestoreDocumentId type
docs for why). Use id.as_str().to_string() when an owned copy is genuinely needed.
Trait Implementations§
Source§impl AsRef<str> for FirestoreCollectionId
impl AsRef<str> for FirestoreCollectionId
Source§impl Borrow<str> for FirestoreCollectionId
impl Borrow<str> for FirestoreCollectionId
Source§impl Clone for FirestoreCollectionId
impl Clone for FirestoreCollectionId
Source§impl Debug for FirestoreCollectionId
impl Debug for FirestoreCollectionId
Source§impl<'de> Deserialize<'de> for FirestoreCollectionId
impl<'de> Deserialize<'de> for FirestoreCollectionId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for FirestoreCollectionId
impl Display for FirestoreCollectionId
impl Eq for FirestoreCollectionId
Source§impl From<&FirestoreCollectionId> for FirestoreQueryCollection
impl From<&FirestoreCollectionId> for FirestoreQueryCollection
Source§fn from(collection_id: &FirestoreCollectionId) -> Self
fn from(collection_id: &FirestoreCollectionId) -> Self
Source§impl From<FirestoreCollectionId> for FirestoreQueryCollection
impl From<FirestoreCollectionId> for FirestoreQueryCollection
Source§fn from(collection_id: FirestoreCollectionId) -> Self
fn from(collection_id: FirestoreCollectionId) -> Self
Source§impl FromStr for FirestoreCollectionId
impl FromStr for FirestoreCollectionId
Source§impl Hash for FirestoreCollectionId
impl Hash for FirestoreCollectionId
Source§impl Ord for FirestoreCollectionId
impl Ord for FirestoreCollectionId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for FirestoreCollectionId
impl PartialEq for FirestoreCollectionId
Source§impl PartialEq<&str> for FirestoreCollectionId
impl PartialEq<&str> for FirestoreCollectionId
Source§impl PartialEq<FirestoreCollectionId> for str
impl PartialEq<FirestoreCollectionId> for str
Source§impl PartialEq<FirestoreCollectionId> for &str
impl PartialEq<FirestoreCollectionId> for &str
Source§impl PartialEq<FirestoreCollectionId> for String
impl PartialEq<FirestoreCollectionId> for String
Source§impl PartialEq<String> for FirestoreCollectionId
impl PartialEq<String> for FirestoreCollectionId
Source§impl PartialEq<str> for FirestoreCollectionId
impl PartialEq<str> for FirestoreCollectionId
Source§impl PartialOrd for FirestoreCollectionId
impl PartialOrd for FirestoreCollectionId
Source§impl Serialize for FirestoreCollectionId
impl Serialize for FirestoreCollectionId
impl StructuralPartialEq for FirestoreCollectionId
Source§impl TryFrom<&str> for FirestoreCollectionId
impl TryFrom<&str> for FirestoreCollectionId
Auto Trait Implementations§
impl Freeze for FirestoreCollectionId
impl RefUnwindSafe for FirestoreCollectionId
impl Send for FirestoreCollectionId
impl Sync for FirestoreCollectionId
impl Unpin for FirestoreCollectionId
impl UnsafeUnpin for FirestoreCollectionId
impl UnwindSafe for FirestoreCollectionId
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request