Update to the 2018 edition

Only 2 years later :eyeroll:
master
Paul Woolcock 4 years ago
parent 17c727f5c6
commit 16bc060407
  1. 1
      Cargo.toml
  2. 4
      examples/follow_profile.rs
  3. 4
      examples/follows_me.rs
  4. 4
      examples/home_timeline.rs
  5. 4
      examples/print_your_profile.rs
  6. 8
      examples/register/mod.rs
  7. 4
      examples/search.rs
  8. 4
      examples/upload_photo.rs
  9. 30158
      macro-dbg
  10. 4
      src/apps.rs
  11. 2
      src/entities/account.rs
  12. 2
      src/entities/event.rs
  13. 4
      src/entities/itemsiter.rs
  14. 4
      src/entities/status.rs
  15. 8
      src/errors.rs
  16. 8
      src/helpers/cli.rs
  17. 4
      src/helpers/env.rs
  18. 4
      src/helpers/json.rs
  19. 6
      src/helpers/toml.rs
  20. 2
      src/http_send.rs
  21. 38
      src/lib.rs
  22. 12
      src/mastodon_client.rs
  23. 4
      src/page.rs
  24. 16
      src/registration.rs
  25. 2
      src/requests/filter.rs
  26. 10
      src/requests/push.rs
  27. 2
      src/requests/statuses.rs
  28. 10
      src/requests/update_credentials.rs
  29. 2
      src/scopes.rs

@ -8,6 +8,7 @@ readme = "README.md"
repository = "https://github.com/pwoolcoc/elefren.git" repository = "https://github.com/pwoolcoc/elefren.git"
keywords = ["api", "web", "social", "mastodon", "wrapper"] keywords = ["api", "web", "social", "mastodon", "wrapper"]
categories = ["web-programming", "web-programming::http-client", "api-bindings"] categories = ["web-programming", "web-programming::http-client", "api-bindings"]
edition = "2018"
[dependencies] [dependencies]
doc-comment = "0.3" doc-comment = "0.3"

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren; extern crate elefren;
mod register; mod register;
use register::MastodonClient; use crate::register::MastodonClient;
use std::error; use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?; let mastodon = register::get_mastodon_data()?;
let input = register::read_line("Enter the account id you'd like to follow: ")?; let input = register::read_line("Enter the account id you'd like to follow: ")?;
let new_follow = mastodon.follow(input.trim())?; let new_follow = mastodon.follow(input.trim())?;

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren; extern crate elefren;
mod register; mod register;
use register::MastodonClient; use crate::register::MastodonClient;
use std::error; use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?; let mastodon = register::get_mastodon_data()?;
for account in mastodon.follows_me()?.items_iter() { for account in mastodon.follows_me()?.items_iter() {
println!("{}", account.acct); println!("{}", account.acct);

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren; extern crate elefren;
mod register; mod register;
use register::MastodonClient; use crate::register::MastodonClient;
use std::error; use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?; let mastodon = register::get_mastodon_data()?;
let tl = mastodon.get_home_timeline()?; let tl = mastodon.get_home_timeline()?;

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren; extern crate elefren;
mod register; mod register;
use register::MastodonClient; use crate::register::MastodonClient;
use std::error; use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?; let mastodon = register::get_mastodon_data()?;
let you = mastodon.verify_credentials()?; let you = mastodon.verify_credentials()?;

@ -11,14 +11,14 @@ use elefren::helpers::toml;
#[allow(dead_code)] #[allow(dead_code)]
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<Error>> { fn main() -> Result<(), Box<dyn Error>> {
register()?; register()?;
Ok(()) Ok(())
} }
#[allow(dead_code)] #[allow(dead_code)]
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> { pub fn get_mastodon_data() -> Result<Mastodon, Box<dyn Error>> {
if let Ok(data) = toml::from_file("mastodon-data.toml") { if let Ok(data) = toml::from_file("mastodon-data.toml") {
Ok(Mastodon::from(data)) Ok(Mastodon::from(data))
} else { } else {
@ -27,7 +27,7 @@ pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
} }
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
pub fn register() -> Result<Mastodon, Box<Error>> { pub fn register() -> Result<Mastodon, Box<dyn Error>> {
let website = read_line("Please enter your mastodon instance url:")?; let website = read_line("Please enter your mastodon instance url:")?;
let registration = Registration::new(website.trim()) let registration = Registration::new(website.trim())
.client_name("elefren-examples") .client_name("elefren-examples")
@ -43,7 +43,7 @@ pub fn register() -> Result<Mastodon, Box<Error>> {
} }
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
pub fn read_line(message: &str) -> Result<String, Box<Error>> { pub fn read_line(message: &str) -> Result<String, Box<dyn Error>> {
println!("{}", message); println!("{}", message);
let mut input = String::new(); let mut input = String::new();

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren; extern crate elefren;
mod register; mod register;
use register::MastodonClient; use crate::register::MastodonClient;
use std::error; use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?; let mastodon = register::get_mastodon_data()?;
let input = register::read_line("Enter the term you'd like to search: ")?; let input = register::read_line("Enter the term you'd like to search: ")?;
let result = mastodon.search(&input, false)?; let result = mastodon.search(&input, false)?;

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren; extern crate elefren;
mod register; mod register;
use register::MastodonClient; use crate::register::MastodonClient;
use std::error; use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?; let mastodon = register::get_mastodon_data()?;
let input = register::read_line("Enter the path to the photo you'd like to post: ")?; let input = register::read_line("Enter the path to the photo you'd like to post: ")?;

30158
macro-dbg

File diff suppressed because it is too large Load Diff

@ -2,8 +2,8 @@ use std::borrow::Cow;
use try_from::TryInto; use try_from::TryInto;
use errors::{Error, Result}; use crate::errors::{Error, Result};
use scopes::Scopes; use crate::scopes::Scopes;
/// Represents an application that can be registered with a mastodon instance /// Represents an application that can be registered with a mastodon instance
#[derive(Clone, Debug, Default, Serialize, PartialEq)] #[derive(Clone, Debug, Default, Serialize, PartialEq)]

@ -2,7 +2,7 @@
use chrono::prelude::*; use chrono::prelude::*;
use serde::de::{self, Deserialize, Deserializer, Unexpected}; use serde::de::{self, Deserialize, Deserializer, Unexpected};
use status_builder; use crate::status_builder;
use std::path::PathBuf; use std::path::PathBuf;
/// A struct representing an Account. /// A struct representing an Account.

@ -1,4 +1,4 @@
use entities::{notification::Notification, status::Status}; use crate::entities::{notification::Notification, status::Status};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Events that come from the /streaming/user API call /// Events that come from the /streaming/user API call

@ -1,5 +1,5 @@
use http_send::HttpSend; use crate::http_send::HttpSend;
use page::Page; use crate::page::Page;
use serde::Deserialize; use serde::Deserialize;
/// Abstracts away the `next_page` logic into a single stream of items /// Abstracts away the `next_page` logic into a single stream of items

@ -2,8 +2,8 @@
use super::prelude::*; use super::prelude::*;
use chrono::prelude::*; use chrono::prelude::*;
use entities::card::Card; use crate::entities::card::Card;
use status_builder::Visibility; use crate::status_builder::Visibility;
/// A status from the instance. /// A status from the instance.
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]

@ -8,9 +8,9 @@ use serde_json::Error as SerdeError;
use serde_qs::Error as SerdeQsError; use serde_qs::Error as SerdeQsError;
use serde_urlencoded::ser::Error as UrlEncodedError; use serde_urlencoded::ser::Error as UrlEncodedError;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
use tomlcrate::de::Error as TomlDeError; use crate::tomlcrate::de::Error as TomlDeError;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
use tomlcrate::ser::Error as TomlSerError; use crate::tomlcrate::ser::Error as TomlSerError;
use url::ParseError as UrlError; use url::ParseError as UrlError;
use tungstenite::error::Error as WebSocketError; use tungstenite::error::Error as WebSocketError;
@ -128,7 +128,7 @@ macro_rules! from {
$(#[$met])* $(#[$met])*
impl From<$typ> for Error { impl From<$typ> for Error {
fn from(from: $typ) -> Self { fn from(from: $typ) -> Self {
use Error::*; use crate::Error::*;
$variant(from) $variant(from)
} }
} }
@ -237,7 +237,7 @@ mod tests {
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[test] #[test]
fn from_toml_de_error() { fn from_toml_de_error() {
use tomlcrate; use crate::tomlcrate;
let err: TomlDeError = tomlcrate::from_str::<()>("not valid toml").unwrap_err(); let err: TomlDeError = tomlcrate::from_str::<()>("not valid toml").unwrap_err();
let err: Error = Error::from(err); let err: Error = Error::from(err);
assert_is!(err, Error::TomlDe(..)); assert_is!(err, Error::TomlDe(..));

@ -1,9 +1,9 @@
use std::io::{self, BufRead, Write}; use std::io::{self, BufRead, Write};
use errors::Result; use crate::errors::Result;
use http_send::HttpSend; use crate::http_send::HttpSend;
use registration::Registered; use crate::registration::Registered;
use Mastodon; use crate::Mastodon;
/// Finishes the authentication process for the given `Registered` object, /// Finishes the authentication process for the given `Registered` object,
/// using the command-line /// using the command-line

@ -1,7 +1,7 @@
use envy; use envy;
use data::Data; use crate::data::Data;
use Result; use crate::Result;
/// Attempts to deserialize a Data struct from the environment /// Attempts to deserialize a Data struct from the environment
pub fn from_env() -> Result<Data> { pub fn from_env() -> Result<Data> {

@ -6,8 +6,8 @@ use std::{
use serde_json; use serde_json;
use data::Data; use crate::data::Data;
use Result; use crate::Result;
/// Attempts to deserialize a Data struct from a string /// Attempts to deserialize a Data struct from a string
pub fn from_str(s: &str) -> Result<Data> { pub fn from_str(s: &str) -> Result<Data> {

@ -4,10 +4,10 @@ use std::{
path::Path, path::Path,
}; };
use tomlcrate; use crate::tomlcrate;
use data::Data; use crate::data::Data;
use Result; use crate::Result;
/// Attempts to deserialize a Data struct from a string /// Attempts to deserialize a Data struct from a string
pub fn from_str(s: &str) -> Result<Data> { pub fn from_str(s: &str) -> Result<Data> {

@ -1,6 +1,6 @@
use reqwest::{Client, Request, RequestBuilder, Response}; use reqwest::{Client, Request, RequestBuilder, Response};
use std::fmt::Debug; use std::fmt::Debug;
use Result; use crate::Result;
/// Abstracts away the process of turning an HTTP request into an HTTP response /// Abstracts away the process of turning an HTTP request into an HTTP response
pub trait HttpSend: Clone + Debug { pub trait HttpSend: Clone + Debug {

@ -5,9 +5,9 @@
//! ```no_run //! ```no_run
//! # extern crate elefren; //! # extern crate elefren;
//! # fn main() { //! # fn main() {
//! # try().unwrap(); //! # run().unwrap();
//! # } //! # }
//! # fn try() -> elefren::Result<()> { //! # fn run() -> elefren::Result<()> {
//! use elefren::{helpers::cli, prelude::*}; //! use elefren::{helpers::cli, prelude::*};
//! //!
//! let registration = Registration::new("https://mastodon.social") //! let registration = Registration::new("https://mastodon.social")
@ -114,23 +114,23 @@ use reqwest::{Client, RequestBuilder, Response};
use tap_reader::Tap; use tap_reader::Tap;
use tungstenite::client::AutoStream; use tungstenite::client::AutoStream;
use entities::prelude::*; use crate::entities::prelude::*;
use http_send::{HttpSend, HttpSender}; use crate::http_send::{HttpSend, HttpSender};
use page::Page; use crate::page::Page;
pub use data::Data; pub use crate::data::Data;
pub use errors::{ApiError, Error, Result}; pub use crate::errors::{ApiError, Error, Result};
pub use isolang::Language; pub use isolang::Language;
pub use mastodon_client::{MastodonClient, MastodonUnauthenticated}; pub use crate::mastodon_client::{MastodonClient, MastodonUnauthenticated};
pub use registration::Registration; pub use crate::registration::Registration;
pub use requests::{ pub use crate::requests::{
AddFilterRequest, AddFilterRequest,
AddPushRequest, AddPushRequest,
StatusesRequest, StatusesRequest,
UpdateCredsRequest, UpdateCredsRequest,
UpdatePushRequest, UpdatePushRequest,
}; };
pub use status_builder::{NewStatus, StatusBuilder}; pub use crate::status_builder::{NewStatus, StatusBuilder};
/// Registering your App /// Registering your App
pub mod apps; pub mod apps;
@ -159,14 +159,14 @@ pub mod status_builder;
mod macros; mod macros;
/// Automatically import the things you need /// Automatically import the things you need
pub mod prelude { pub mod prelude {
pub use scopes::Scopes; pub use crate::scopes::Scopes;
pub use Data; pub use crate::Data;
pub use Mastodon; pub use crate::Mastodon;
pub use MastodonClient; pub use crate::MastodonClient;
pub use NewStatus; pub use crate::NewStatus;
pub use Registration; pub use crate::Registration;
pub use StatusBuilder; pub use crate::StatusBuilder;
pub use StatusesRequest; pub use crate::StatusesRequest;
} }
/// Your mastodon application client, handles all requests to and from Mastodon. /// Your mastodon application client, handles all requests to and from Mastodon.

@ -1,17 +1,17 @@
use std::borrow::Cow; use std::borrow::Cow;
use entities::prelude::*; use crate::entities::prelude::*;
use errors::Result; use crate::errors::Result;
use http_send::{HttpSend, HttpSender}; use crate::http_send::{HttpSend, HttpSender};
use page::Page; use crate::page::Page;
use requests::{ use crate::requests::{
AddFilterRequest, AddFilterRequest,
AddPushRequest, AddPushRequest,
StatusesRequest, StatusesRequest,
UpdateCredsRequest, UpdateCredsRequest,
UpdatePushRequest, UpdatePushRequest,
}; };
use status_builder::NewStatus; use crate::status_builder::NewStatus;
/// Represents the set of methods that a Mastodon Client can do, so that /// Represents the set of methods that a Mastodon Client can do, so that
/// implementations might be swapped out for testing /// implementations might be swapped out for testing

@ -1,11 +1,11 @@
use super::{deserialise, Mastodon, Result}; use super::{deserialise, Mastodon, Result};
use entities::itemsiter::ItemsIter; use crate::entities::itemsiter::ItemsIter;
use hyper_old_types::header::{parsing, Link, RelationType}; use hyper_old_types::header::{parsing, Link, RelationType};
use reqwest::{header::LINK, Response}; use reqwest::{header::LINK, Response};
use serde::Deserialize; use serde::Deserialize;
use url::Url; use url::Url;
use http_send::HttpSend; use crate::http_send::HttpSend;
macro_rules! pages { macro_rules! pages {
($($direction:ident: $fun:ident),*) => { ($($direction:ident: $fun:ident),*) => {

@ -4,14 +4,14 @@ use reqwest::{Client, RequestBuilder, Response};
use try_from::TryInto; use try_from::TryInto;
use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use apps::{App, AppBuilder}; use crate::apps::{App, AppBuilder};
use http_send::{HttpSend, HttpSender}; use crate::http_send::{HttpSend, HttpSender};
use scopes::Scopes; use crate::scopes::Scopes;
use Data; use crate::Data;
use Error; use crate::Error;
use Mastodon; use crate::Mastodon;
use MastodonBuilder; use crate::MastodonBuilder;
use Result; use crate::Result;
const DEFAULT_REDIRECT_URI: &'static str = "urn:ietf:wg:oauth:2.0:oob"; const DEFAULT_REDIRECT_URI: &'static str = "urn:ietf:wg:oauth:2.0:oob";

@ -1,4 +1,4 @@
use entities::filter::FilterContext; use crate::entities::filter::FilterContext;
use std::time::Duration; use std::time::Duration;
/// Form used to create a filter /// Form used to create a filter

@ -1,5 +1,5 @@
use entities::push::{add_subscription, update_data}; use crate::entities::push::{add_subscription, update_data};
use errors::Result; use crate::errors::Result;
/// Container for the key & auth strings for an AddPushRequest /// Container for the key & auth strings for an AddPushRequest
/// ///
@ -169,7 +169,7 @@ impl AddPushRequest {
} }
pub(crate) fn build(&self) -> Result<add_subscription::Form> { pub(crate) fn build(&self) -> Result<add_subscription::Form> {
use entities::push::{ use crate::entities::push::{
add_subscription::{Data, Form, Keys, Subscription}, add_subscription::{Data, Form, Keys, Subscription},
Alerts, Alerts,
}; };
@ -326,7 +326,7 @@ impl UpdatePushRequest {
} }
pub(crate) fn build(&self) -> update_data::Form { pub(crate) fn build(&self) -> update_data::Form {
use entities::push::{ use crate::entities::push::{
update_data::{Data, Form}, update_data::{Data, Form},
Alerts, Alerts,
}; };
@ -361,7 +361,7 @@ impl UpdatePushRequest {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use entities::push::{add_subscription, update_data, Alerts}; use crate::entities::push::{add_subscription, update_data, Alerts};
#[test] #[test]
fn test_keys_new() { fn test_keys_new() {

@ -1,4 +1,4 @@
use errors::Error; use crate::errors::Error;
use serde_qs; use serde_qs;
use std::{borrow::Cow, convert::Into}; use std::{borrow::Cow, convert::Into};

@ -3,9 +3,9 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use entities::account::{Credentials, MetadataField, UpdateSource}; use crate::entities::account::{Credentials, MetadataField, UpdateSource};
use errors::Result; use crate::errors::Result;
use status_builder; use crate::status_builder;
/// Builder to pass to the Mastodon::update_credentials method /// Builder to pass to the Mastodon::update_credentials method
/// ///
@ -202,8 +202,8 @@ impl UpdateCredsRequest {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use entities::account::{Credentials, MetadataField, UpdateSource}; use crate::entities::account::{Credentials, MetadataField, UpdateSource};
use status_builder::Visibility; use crate::status_builder::Visibility;
#[test] #[test]
fn test_update_creds_request_new() { fn test_update_creds_request_new() {

@ -8,7 +8,7 @@ use std::{
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use errors::Error; use crate::errors::Error;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use serde::de::{self, Visitor}; use serde::de::{self, Visitor};

Loading…
Cancel
Save