Module egg_mode::entities [] [src]

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.

Using indices and URLs

When displaying text with accompanied entities, be wary about how you use the accompanied indices. The indices given by Twitter reference the graphemes in the tweet, so something like char_indices will fall flat when faced with text that uses combining characters. The unicode-segmentation crate provides a means to iterate over the graphemes of a string, allowing you to make sure you hyperlink the right range of characters in the text.

Alternately, when substituting URLs for display, str::replace works just fine.

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.