[][src]Module egg_mode::entities

Data structures containing extracted URL, mention, tag, and media information.

These structures are meant to be received in an API call to describe the data they accompany. For example, a UrlEntity describes a hyperlink in a tweet or user description text, and a HashtagEntity describes a hashtag or stock symbol extracted from a tweet.

For more information on the data in these structures, see Twitter's documentation for Entities and Entities in Objects.

Entity Ranges

Entities that refer to elements within a text have a range field that contains the text span that is being referenced. The numbers in question are byte offsets, so if you have an entity that you'd like to slice out of the source text, you can use the indices directly in slicing operations:

let slice = &text[entity.range.0..entity.range.1];

Shortened, Display, and Expanded URLs

URL and Media entities contain references to a URL within their parent text. However, due to the nature of how Twitter handles URLs in tweets and user bios, each entity struct has three URLs within it:

  • url: This is the t.co shortened URL as returned directly from twitter. This is what contributes to character count in tweets and user bios.
  • expanded_url: This is the original URL the user entered in their tweet. While it is given to API client, Twitter recommends still sending users to the shortened link, for analytics purposes. Twitter Web uses this field to supply hover-text for where the URL resolves to.
  • display_url: This is a truncated version of expanded_url, meant to be displayed inline with the parent text. This is useful to show users where the link resolves to, without potentially filling up a lot of space with the fullly expanded URL.

Structs

HashtagEntity

Represents a hashtag or symbol extracted from another piece of text.

MediaEntity

Represents a piece of media attached to a tweet.

MediaSize

Represents the dimensions of a media file.

MediaSizes

Represents the available sizes for a media file.

MentionEntity

Represnts a user mention extracted from another piece of text.

UrlEntity

Represents a link extracted from another piece of text.

VideoInfo

Represents metadata specific to videos.

VideoVariant

Represents information about a specific encoding of a video.

Enums

MediaType

Represents the types of media that can be attached to a tweet.

ResizeMode

Represents how an image has been resized for a given size variant.