pub struct ContentId(/* private fields */);Expand description
An unresolved reference to a content item — a post or a comment, not yet known which.
This is the wire type. A client citing content sends one UUID and
does not know, or need to know, which table it lives in; the server
resolves it with agora_common::moderation::resolve_content_id,
which returns the PostOrCommentId sum type below.
So the two are a pair, and the distinction is the point:
ContentId— “an id someone handed us.” Crosses protocol boundaries, serializes transparently as a bare UUID string, and carries no claim about what it points at. May not resolve at all.PostOrCommentId— “an id we have resolved.” Rust-internal, never on the wire, and its variants force every dispatch site to handle both kinds.
Resolve at the boundary, then work with the sum type. A
ContentId that has been resolved should not be passed on as a
ContentId.
Implementations§
Trait Implementations§
impl Copy for ContentId
Source§impl<'de> Deserialize<'de> for ContentId
impl<'de> Deserialize<'de> for ContentId
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>,
impl Eq for ContentId
Source§impl From<ContentId> for ModerationTargetId
Content is always a legal moderation target, so this narrowing is
sound in the same way the others are.
impl From<ContentId> for ModerationTargetId
Content is always a legal moderation target, so this narrowing is sound in the same way the others are.
Source§impl From<PostId> for ContentId
A ContentId can be produced from anything already known to be
content — narrowing to “an id” from “an id we resolved” is always
sound. The reverse needs a database lookup and is
resolve_content_id’s job, which is why there is no From for it.
impl From<PostId> for ContentId
A ContentId can be produced from anything already known to be
content — narrowing to “an id” from “an id we resolved” is always
sound. The reverse needs a database lookup and is
resolve_content_id’s job, which is why there is no From for it.
Source§impl From<PostOrCommentId> for ContentId
impl From<PostOrCommentId> for ContentId
Source§fn from(id: PostOrCommentId) -> Self
fn from(id: PostOrCommentId) -> Self
Source§impl FromStr for ContentId
Every id round-trips through its own Display.
impl FromStr for ContentId
Every id round-trips through its own Display.
Without this, anything that parses an id from a string — clap
value_parsers, query strings, config files — has to widen the
field back to a bare Uuid at the boundary and convert by
hand, which is the exact laundering the newtype exists to
prevent. agora-cli carried a hand-written
parse_moderation_action_id for precisely this reason.