pub struct CompactReaction {
pub id: [u8; 32],
pub author_idx: u16,
pub emoji: Box<str>,
pub emoji_url: Option<Box<str>>,
}Expand description
Memory-efficient reaction with binary IDs and interned author.
Compared to the regular Reaction struct (~292 bytes with heap):
- IDs use
[u8; 32]instead of hex String (saves ~56 bytes each) - Author uses u16 index into interner (saves ~86 bytes)
- Emoji uses Box
(saves 8 bytes, supports custom emoji like :cat_heart_eyes:) - Total: ~82 bytes vs ~292 bytes (72% savings!)
Fields§
§id: [u8; 32]Reaction event ID as binary
Author npub index (interned via NpubInterner)
emoji: Box<str>Emoji string (supports standard emoji and custom like :cat_heart_eyes:)
emoji_url: Option<Box<str>>NIP-30 custom-emoji URL when the reaction is :shortcode: form.
Boxed so the cold path (stock unicode reactions) stays 8 bytes.
Implementations§
Source§impl CompactReaction
impl CompactReaction
Sourcepub fn from_reaction(reaction: &Reaction, interner: &mut NpubInterner) -> Self
pub fn from_reaction(reaction: &Reaction, interner: &mut NpubInterner) -> Self
Convert from regular Reaction, interning author
Sourcepub fn from_reaction_owned(
reaction: Reaction,
interner: &mut NpubInterner,
) -> Self
pub fn from_reaction_owned( reaction: Reaction, interner: &mut NpubInterner, ) -> Self
Convert from regular Reaction (owned), interning author
Sourcepub fn to_reaction(
&self,
parent_id: &[u8; 32],
interner: &NpubInterner,
) -> Reaction
pub fn to_reaction( &self, parent_id: &[u8; 32], interner: &NpubInterner, ) -> Reaction
Convert back to regular Reaction, resolving author from interner.
parent_id is the reacted-to message’s binary event id: a CompactReaction
is always nested inside that message, so its id IS the reference (the field
used to be stored redundantly on every reaction).
Trait Implementations§
Source§impl Clone for CompactReaction
impl Clone for CompactReaction
Source§fn clone(&self) -> CompactReaction
fn clone(&self) -> CompactReaction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompactReaction
impl Debug for CompactReaction
Auto Trait Implementations§
impl Freeze for CompactReaction
impl RefUnwindSafe for CompactReaction
impl Send for CompactReaction
impl Sync for CompactReaction
impl Unpin for CompactReaction
impl UnsafeUnpin for CompactReaction
impl UnwindSafe for CompactReaction
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more