Skip to main content

AttributedRange

Struct AttributedRange 

Source
pub struct AttributedRange {
    pub start: usize,
    pub end: usize,
    pub effects: Vec<TextEffect>,
    pub attachment: Option<AttachmentMeta>,
    pub emoji_image: bool,
}
Expand description

One attribute run of a message’s NSAttributedString body: a byte range into the Message’s text plus every attribute applied to it.

A range is a text range when attachment is None and an attachment range (a \u{FFFC} placeholder for an inline attachment) when it is Some. Effects, styles, and the inline-emoji hint apply to either kind. The typedstream attribute dictionary is a flat bag, so an attachment range can also carry, say, an Animated effect.

Ranges that share a __kIMMessagePartAttributeName index are grouped into one BubbleComponent::Run. For example, message text with a Mention like:

let message_text = "What's up, Christopher?";

parses into a single run of 3 ranges:

use imessage_database::message_types::text_effects::text_effect::TextEffect;
use imessage_database::tables::messages::models::{AttributedRange, BubbleComponent};

let result = vec![BubbleComponent::Run(vec![
    AttributedRange::text(0, 11, vec![TextEffect::Default]),  // `What's up, `
    AttributedRange::text(11, 22, vec![TextEffect::Mention("+5558675309".to_string())]), // `Christopher`
    AttributedRange::text(22, 23, vec![TextEffect::Default])  // `?`
])];

Fields§

§start: usize

Start byte index in the message text.

§end: usize

End byte index in the message text.

§effects: Vec<TextEffect>

Effects applied to this range.

§attachment: Option<AttachmentMeta>

Some when this range is a \u{FFFC} placeholder for an attachment. The attachment’s metadata travels here; effects still apply alongside.

§emoji_image: bool

true when the range carries __kIMEmojiImageAttributeName–Apple’s hint to render the attachment inline–like an emoji (observed on genmoji, Memoji, and custom sticker ranges).

Implementations§

Source§

impl AttributedRange

Source

pub fn text(start: usize, end: usize, effects: Vec<TextEffect>) -> Self

Build a text range (no attachment, no inline-emoji hint) with the specified start index, end index, and text effects.

Source

pub fn attachment(start: usize, end: usize, meta: AttachmentMeta) -> Self

Build an attachment range carrying the given AttachmentMeta, with no inline-emoji hint.

Source

pub fn inline_attachment(start: usize, end: usize, meta: AttachmentMeta) -> Self

Build an inline-rendered attachment range, one Apple flagged with __kIMEmojiImageAttributeName to render inline like an emoji (a Memoji, genmoji, or custom sticker placed amongst text).

Source

pub fn is_attachment(&self) -> bool

true when this range stands in for an attachment rather than text.

Trait Implementations§

Source§

impl Clone for AttributedRange

Source§

fn clone(&self) -> AttributedRange

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 AttributedRange

Source§

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

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

impl PartialEq for AttributedRange

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for AttributedRange

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, 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> 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.