Skip to main content

CompactAttachment

Struct CompactAttachment 

Source
pub struct CompactAttachment {
    pub key: [u8; 32],
    pub nonce: [u8; 16],
    pub size: u64,
    pub url: Box<str>,
    /* private fields */
}
Expand description

Memory-efficient attachment: binary hashes, the extension as a code, the local path derived from the id or name when it can be, image metadata in one allocation, and the rarely-set fields behind one box.

Fields§

§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

§url: Box<str>

Host URL (blossom server, etc.)

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 verified(&self) -> bool

Source

pub fn set_verified(&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 extension(&self) -> &str

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

Source

pub fn has_path(&self) -> bool

Whether a local path is set, without building it.

Source

pub fn path(&self) -> Cow<'_, str>

Local file path (empty if not downloaded). Allocates only for a derived path.

Source

pub fn id(&self) -> &[u8; 32]

Source

pub fn name(&self) -> &str

Source

pub fn flags(&self) -> AttachmentFlags

Source

pub fn set_id(&mut self, id: [u8; 32])

The path and original hash stay what they were: both may be derived from the id.

Source

pub fn set_name(&mut self, name: &str)

The path stays what it was: it may be derived from the name.

Source

pub fn set_path(&mut self, path: String)

Source

pub fn img_meta(&self) -> Option<ImageMetadata>

Image dimensions and thumbhash (only for images/videos)

Source

pub fn has_img_meta(&self) -> bool

Source

pub fn set_img_meta(&mut self, meta: Option<&ImageMetadata>)

Source

pub fn original_hash(&self) -> Option<[u8; 32]>

Original file hash before encryption

Source

pub fn group_id(&self) -> Option<[u8; 32]>

Legacy group ID for key derivation

Source

pub fn webxdc_topic(&self) -> Option<&str>

WebXDC topic (Mini Apps only)

Source

pub fn fallback_urls(&self) -> &[Box<str>]

Mirror URLs for the same ciphertext

Source

pub fn set_fallback_urls(&mut self, urls: impl IntoIterator<Item = Box<str>>)

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) -> Self

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> MaybeSend for T
where T: Send + ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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