Skip to main content

CompactAttachment

Struct CompactAttachment 

Source
pub struct CompactAttachment {
Show 15 fields pub id: [u8; 32], pub key: [u8; 32], pub nonce: [u8; 16], pub size: u64, pub flags: AttachmentFlags, pub extension: Box<str>, pub url: Box<str>, pub path: Box<str>, pub img_meta: Option<Box<ImageMetadata>>, pub group_id: Option<Box<[u8; 32]>>, pub original_hash: Option<Box<[u8; 32]>>, pub webxdc_topic: Option<Box<str>>, pub mls_filename: Option<Box<str>>, pub scheme_version: Option<Box<str>>, pub name: String,
}
Expand description

Memory-efficient attachment with binary hashes and compact strings.

Compared to the regular Attachment struct (~320+ bytes):

  • id (SHA256): [u8; 32] instead of hex String (saves ~56 bytes)
  • key: [u8; 32] instead of String (saves ~56 bytes)
  • nonce: [u8; 16] instead of String (saves ~32 bytes)
  • Bools packed into AttachmentFlags (saves padding)
  • Strings use Box (saves 8 bytes each)
  • Rare fields boxed (saves ~100+ bytes when None)
  • Total: ~120 bytes vs ~320 bytes (62% savings!)

Fields§

§id: [u8; 32]

SHA256 file hash as binary (was hex String)

§key: [u8; 32]

Encryption key - 32 bytes (empty = legacy derived)

§nonce: [u8; 16]

Encryption nonce - 16 bytes (AES-256-GCM with 0xChat compatibility)

§size: u64

File size in bytes

§flags: AttachmentFlags

Packed boolean flags (downloading, downloaded)

§extension: Box<str>

File extension (e.g., “png”, “mp4”)

§url: Box<str>

Host URL (blossom server, etc.)

§path: Box<str>

Local file path (empty if not downloaded)

§img_meta: Option<Box<ImageMetadata>>

Image metadata (only for images/videos)

§group_id: Option<Box<[u8; 32]>>

Legacy group ID for key derivation

§original_hash: Option<Box<[u8; 32]>>

Original file hash before encryption

§webxdc_topic: Option<Box<str>>

WebXDC topic (Mini Apps only - very rare)

§mls_filename: Option<Box<str>>

Legacy filename for AAD

§scheme_version: Option<Box<str>>

Scheme version (e.g., “mip04-v1”)

§name: String

Original filename (e.g. “memories.zip”). Empty = fallback to {hash}.{ext}

Implementations§

Source§

impl CompactAttachment

Source

pub fn downloaded(&self) -> bool

Source

pub fn downloading(&self) -> bool

Source

pub fn set_downloaded(&mut self, value: bool)

Source

pub fn set_downloading(&mut self, value: bool)

Source

pub fn id_eq(&self, hex_id: &str) -> bool

Check if this attachment’s ID matches a hex string

Source

pub fn id_hex(&self) -> String

Get file ID as hex string

Source

pub fn key_hex(&self) -> String

Get encryption key as hex string (empty if zeros)

Source

pub fn nonce_hex(&self) -> String

Get nonce as hex string (empty if zeros, respects original length)

Source

pub fn from_attachment(att: &Attachment) -> Self

Convert from regular Attachment (borrowed)

Source

pub fn from_attachment_owned(att: Attachment) -> Self

Convert from regular Attachment (owned) - zero-copy where possible

Source

pub fn to_attachment(&self) -> Attachment

Convert back to regular Attachment

Trait Implementations§

Source§

impl Clone for CompactAttachment

Source§

fn clone(&self) -> CompactAttachment

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 Debug for CompactAttachment

Source§

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

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

impl DeepSize for CompactAttachment

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<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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, 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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more