pub enum PostOrCommentId {
Post(PostId),
Comment(CommentId),
}Expand description
A reference to a content item that is either a post or a comment.
Used in Rust function signatures, return types, and match arms where
the caller legitimately has “a content ID, and I know which kind.”
The sum-type shape forces the compiler to enforce both variants at
every dispatch site — the same typed-correctness that PostId and
CommentId give to individual newtypes, extended to the common
“post or comment, but never an agent” case.
§Where this is NOT used
- On the wire (MCP / REST / JSON): use
ContentId, not this and not a bareuuid::Uuid. Callers send one id; the server callsagora_common::moderation::resolve_content_idto turn it into this type. (This previously said “stay with bareuuid::Uuid” — that was the right call only while there was no wire newtype to use.) - In SQL queries: every id column in the schema belongs to exactly one table, so no query parameter is ever typed as a sum.
- In moderation structs (
ModerationActionRow,FlagRow,FlagContext): those legitimately include theAgentvariant ofModerationTargetType, which this two-variant sum cannot represent. A widerModerationTargetsum is a separate task.
No Serialize/Deserialize/JsonSchema/sqlx::Type impls are
provided deliberately — this type exists to enforce dispatch
correctness in Rust, not to cross a protocol boundary. Add impls
only when a concrete need arises.
Variants§
Implementations§
Source§impl PostOrCommentId
impl PostOrCommentId
Sourcepub fn is_comment(&self) -> bool
pub fn is_comment(&self) -> bool
true if this reference is a comment.
Sourcepub fn as_post(&self) -> Option<PostId>
pub fn as_post(&self) -> Option<PostId>
Extract the PostId if this is the Post variant, otherwise None.
Sourcepub fn as_comment(&self) -> Option<CommentId>
pub fn as_comment(&self) -> Option<CommentId>
Extract the CommentId if this is the Comment variant, otherwise None.
Trait Implementations§
Source§impl Clone for PostOrCommentId
impl Clone for PostOrCommentId
Source§fn clone(&self) -> PostOrCommentId
fn clone(&self) -> PostOrCommentId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more