Crate egg_mode [] [src]

A library for interacting with Twitter.


egg-mode is a Twitter library that aims to make as few assumptions about the user's codebase as possible. Endpoints are exposed as bare functions where authentication details are passed in as arguments, rather than as builder functions of a root "service" manager. The only exceptions to this guideline are endpoints with many optional parameters, like posting a status update or updating the metadata of a list.

To use the Twitter API, there are some extra steps you need to do, both inside and outside of your app code. Find the Authentication Overview and quick start guide in the Token documentation. The following examples already have a token on hand. In addition, using asynchronous network calls, the various methods of this library assume the presence of a tokio Core whose Handle you pass to any given call. These are also assumed to be present in each example.

To load the profile information of a single user:

let rustlang ="rustlang", &token, &handle)).unwrap();

println!("{} (@{})",, rustlang.screen_name);

To post a new tweet:

use egg_mode::tweet::DraftTweet;

let post ="Hey Twitter!").send(&token, &handle)).unwrap();

Types and Functions

All of the main content of egg-mode is in submodules, but there are a few things here in the crate root. To wit, it contains items related to authentication and a couple items that all the submodules use.


Every method that calls Twitter and carries rate-limit information wraps its return value in a Response struct, that transmits this information to your app. From there, you can handle the rate-limit information to hold off on that kind of request, or simply grab its response field to get the output of whatever method you called. Response also implements Deref, so for the most part you can access fields of the final result without having to grab the response field directly.

Response also has IntoIterator implementations and iterator creation methods that echo those on Vec<T>, for methods that return Vecs. These methods and iterator types distribute the rate-limit information across each iteration.

TwitterFuture<'a, T>

Any method that requires a network call will return a handle to the pending network call, in most cases the type TwitterFuture. This type (and any other *Future in this library) implements the Future trait, for use as an asynchronous network call. All Future implementations in this library use the Error enum as their Error value. For more information on how to use the Future trait, check out the Tokio documentation guides.

In addition, there is also a FutureResponse type alias, that corresponds to TwitterFuture<'a, Response<T>>, for methods that return rate-limit information.

Authentication Types/Functions

The remaining types and methods are explained as part of the authentication overview, with the exception of verify_tokens, which is a simple method to ensure a given token is still valid.


As there are many actions available in the Twitter API, egg-mode divides them roughly into several modules by their shared purpose. Here's a sort of high-level overview, in rough order from "most important" to "less directly used":

Primary actions

These could be considered the "core" actions within the Twitter API that egg-mode has made available.

  • tweet: This module lets you act on tweets. Here you can find actions to load a user's timeline, post a new tweet, or like and retweet individual posts.
  • user: This module lets you act on users, be it by following or unfollowing them, loading their profile information, blocking or muting them, or showing the relationship between two users.
  • search: Due to the complexity of searching for tweets, it gets its own module.
  • direct: Here you can work with a user's Direct Messages, either by loading DMs they've sent or received, or by sending new ones.
  • list: This module lets you act on lists, from creating and deleting them, adding and removing users, or loading the posts made by their members.
  • text: Text processing functions to count characters in new tweets and extract links and hashtags for highlighting and linking.

Secondary actions

These modules still contain direct actions for Twitter, but they can be considered as having more of a helper role than something you might use directly.

  • place: Here are actions that look up physical locations that can be attached to tweets, as well at the Place struct that appears on tweets with locations attached.
  • service: These are some miscellaneous methods that show information about the Twitter service as a whole, like loading the maximum length of URLs or loading the current Terms of Service or Privacy Policy.

Helper structs

These modules contain some implementations that wrap some pattern seen in multiple "action" modules.

  • cursor: This contains a helper trait and some helper structs that allow effective cursoring through certain collections of results from Twitter.
  • entities: Whenever some text can be returned that may contain links, hashtags, media, or user mentions, its metadata is parsed into something that lives in this module.
  • error: Any interaction with Twitter may result in an error condition, be it from finding a tweet or user that doesn't exist or the network connection being unavailable. All the error types are aggregated into an enum in this module.



Types and traits to navigate cursored collections.


Structs and methods for working with direct messages.


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


A composite error type for errors that can occur while interacting with Twitter.


Structs and functions for working with lists.


Types and methods for looking up locations.


Structs and methods for searching for tweets.


Methods to inquire about the Twitter service itself.


Helper methods for character counting and entity extraction.


Structs and functions for working with statuses and timelines.


Structs and methods for pulling user information from Twitter.



Future which yields an access token when it finishes.


A key/secret pair representing an OAuth token.


A helper struct to wrap response data with accompanying rate limit information.


Iterator returned by calling .into_iter() on a Response<Vec<T>>.


Iterator returned by calling .iter_mut() on a Response<Vec<T>>.


Iterator returned by calling .iter() on a Response<Vec<T>>.


A Future that will resolve to a complete Twitter response.



A token that can be used to sign requests to Twitter.



With the given OAuth tokens and verifier, ask Twitter for an access KeyPair that can be used to sign further requests to the Twitter API.


With the given request KeyPair, return a URL to redirect a user to so they can accept or reject an authorization request.


With the given request KeyPair, return a URL that a user can access to accept or reject an authorization request.


With the given consumer KeyPair, request the current Bearer token to perform Application-only authentication.


Invalidate the given Bearer token using the given consumer KeyPair. Upon success, the future returned by this function yields the Token that was just invalidated.


With the given consumer KeyPair, ask Twitter for a request KeyPair that can be used to request access to the user's account.


If the given tokens are valid, return the user information for the authenticated user.

Type Definitions


Type alias for futures that resolve to responses from Twitter.