Update to the 2018 edition

Only 2 years later :eyeroll:
master
Paul Woolcock 5 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"
keywords = ["api", "web", "social", "mastodon", "wrapper"]
categories = ["web-programming", "web-programming::http-client", "api-bindings"]
edition = "2018"
[dependencies]
doc-comment = "0.3"

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

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

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

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

@ -11,14 +11,14 @@ use elefren::helpers::toml;
#[allow(dead_code)]
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<Error>> {
fn main() -> Result<(), Box<dyn Error>> {
register()?;
Ok(())
}
#[allow(dead_code)]
#[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") {
Ok(Mastodon::from(data))
} else {
@ -27,7 +27,7 @@ pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
}
#[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 registration = Registration::new(website.trim())
.client_name("elefren-examples")
@ -43,7 +43,7 @@ pub fn register() -> Result<Mastodon, Box<Error>> {
}
#[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);
let mut input = String::new();

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

@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
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 errors::{Error, Result};
use scopes::Scopes;
use crate::errors::{Error, Result};
use crate::scopes::Scopes;
/// Represents an application that can be registered with a mastodon instance
#[derive(Clone, Debug, Default, Serialize, PartialEq)]

@ -2,7 +2,7 @@
use chrono::prelude::*;
use serde::de::{self, Deserialize, Deserializer, Unexpected};
use status_builder;
use crate::status_builder;
use std::path::PathBuf;
/// 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)]
/// Events that come from the /streaming/user API call

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

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

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

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

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

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

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

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

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

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

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

@ -4,14 +4,14 @@ use reqwest::{Client, RequestBuilder, Response};
use try_from::TryInto;
use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use apps::{App, AppBuilder};
use http_send::{HttpSend, HttpSender};
use scopes::Scopes;
use Data;
use Error;
use Mastodon;
use MastodonBuilder;
use Result;
use crate::apps::{App, AppBuilder};
use crate::http_send::{HttpSend, HttpSender};
use crate::scopes::Scopes;
use crate::Data;
use crate::Error;
use crate::Mastodon;
use crate::MastodonBuilder;
use crate::Result;
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;
/// Form used to create a filter

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

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

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

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

Loading…
Cancel
Save