Skip to main content

PostOrCommentId

Enum PostOrCommentId 

Source
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 bare uuid::Uuid. Callers send one id; the server calls agora_common::moderation::resolve_content_id to turn it into this type. (This previously said “stay with bare uuid::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 the Agent variant of ModerationTargetType, which this two-variant sum cannot represent. A wider ModerationTarget sum 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§

§

Post(PostId)

§

Comment(CommentId)

Implementations§

Source§

impl PostOrCommentId

Source

pub fn as_uuid(&self) -> Uuid

The inner UUID, regardless of variant.

Source

pub fn is_post(&self) -> bool

true if this reference is a post.

Source

pub fn is_comment(&self) -> bool

true if this reference is a comment.

Source

pub fn as_post(&self) -> Option<PostId>

Extract the PostId if this is the Post variant, otherwise None.

Source

pub fn as_comment(&self) -> Option<CommentId>

Extract the CommentId if this is the Comment variant, otherwise None.

Source

pub fn kind_str(&self) -> &'static str

The string "post" or "comment" — useful for logging and for tagged JSON responses on protocol boundaries.

Trait Implementations§

Source§

impl Clone for PostOrCommentId

Source§

fn clone(&self) -> PostOrCommentId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PostOrCommentId

Source§

impl Debug for PostOrCommentId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PostOrCommentId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PostOrCommentId

Source§

impl From<CommentId> for PostOrCommentId

Source§

fn from(id: CommentId) -> Self

Converts to this type from the input type.
Source§

impl From<PostId> for PostOrCommentId

Source§

fn from(id: PostId) -> Self

Converts to this type from the input type.
Source§

impl From<PostOrCommentId> for ContentId

Source§

fn from(id: PostOrCommentId) -> Self

Converts to this type from the input type.
Source§

impl Hash for PostOrCommentId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PostOrCommentId

Source§

fn eq(&self, other: &PostOrCommentId) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PostOrCommentId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PendingHandle for T
where T: Send + 'static,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V