Skip to content

Commit

Permalink
style: group imports
Browse files Browse the repository at this point in the history
requires nightly for `cargo fmt` (`cargo +nightly fmt`). Without nightly it prints warnings but continues to work.
  • Loading branch information
EdJoPaTo committed Sep 17, 2024
1 parent d20ad40 commit 242304b
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 451 deletions.
32 changes: 9 additions & 23 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Test and Build Rust
name: Rust

on:
push:
branches-ignore: ["dependabot/**"]
pull_request:
workflow_dispatch:
schedule:
Expand All @@ -12,16 +13,13 @@ jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: stable
components: rustfmt
- uses: actions/checkout@v4
- run: cargo fmt --check --verbose

clippy:
name: Clippy ${{ matrix.toolchain }}
runs-on: ubuntu-latest
continue-on-error: ${{ (matrix.toolchain == 'beta') || (matrix.toolchain == 'nightly') }}
strategy:
Expand All @@ -34,9 +32,8 @@ jobs:
env:
RUSTFLAGS: --deny warnings
steps:
- name: Setup Rust
- uses: dtolnay/rust-toolchain@master
id: rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: clippy
Expand All @@ -50,7 +47,6 @@ jobs:
- run: cargo doc --offline --all-features --no-deps

features:
name: Features ${{ matrix.toolchain }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -65,16 +61,11 @@ jobs:
env:
RUSTFLAGS: --allow unknown-lints --deny warnings
steps:
- name: Setup Rust
- uses: dtolnay/rust-toolchain@master
id: rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}

- name: Install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- uses: taiki-e/install-action@cargo-hack

- uses: actions/checkout@v4
- run: cargo fetch
Expand All @@ -90,7 +81,6 @@ jobs:
run: cargo hack --keep-going --feature-powerset --no-dev-deps check --offline

test:
name: Test ${{ matrix.toolchain }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
strategy:
Expand All @@ -105,9 +95,8 @@ jobs:
- macos-latest
- windows-latest
steps:
- name: Setup Rust
- uses: dtolnay/rust-toolchain@master
id: rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- uses: actions/checkout@v4
Expand Down Expand Up @@ -149,11 +138,9 @@ jobs:
env:
RUSTFLAGS: --deny warnings
steps:
- name: Setup Rust
- uses: dtolnay/rust-toolchain@stable
id: rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{ matrix.triple }}

- name: Install cargo tools
Expand All @@ -169,5 +156,4 @@ jobs:
key: release-${{ matrix.triple }}-${{ steps.rust.outputs.cachekey }}-${{ hashFiles('**/Cargo.*') }}
path: target/

- name: Build
run: ${{ runner.os == 'Linux' && 'cross' || 'cargo' }} build --release --offline --all-features --target ${{ matrix.triple }}
- run: ${{ runner.os == 'Linux' && 'cross' || 'cargo' }} build --release --offline --all-features --target ${{ matrix.triple }}
10 changes: 6 additions & 4 deletions examples/api_trait_implementation.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use frankenstein::ErrorResponse;
use frankenstein::SendMessageParams;
use frankenstein::TelegramApi;
use isahc::{prelude::*, Request};
use std::path::PathBuf;

use frankenstein::api_params::SendMessageParams;
use frankenstein::response::ErrorResponse;
use frankenstein::TelegramApi;
use isahc::prelude::*;
use isahc::Request;

static TOKEN: &str = "TOKEN";
static BASE_API_URL: &str = "https://api.telegram.org/bot";
static CHAT_ID: i64 = 1;
Expand Down
4 changes: 2 additions & 2 deletions examples/async_custom_client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use frankenstein::AsyncApi;
use frankenstein::AsyncTelegramApi;
use std::time::Duration;

use frankenstein::{AsyncApi, AsyncTelegramApi};

static TOKEN: &str = "API_TOKEN";
static BASE_API_URL: &str = "https://api.telegram.org/bot";

Expand Down
3 changes: 1 addition & 2 deletions examples/async_file_upload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use frankenstein::api_params::SendPhotoParams;
use frankenstein::AsyncApi;
use frankenstein::AsyncTelegramApi;
use frankenstein::{AsyncApi, AsyncTelegramApi};

static TOKEN: &str = "TOKEN";
static CHAT_ID: i64 = 1;
Expand Down
3 changes: 1 addition & 2 deletions examples/async_get_me.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use frankenstein::AsyncApi;
use frankenstein::AsyncTelegramApi;
use frankenstein::{AsyncApi, AsyncTelegramApi};

static TOKEN: &str = "API_TOKEN";

Expand Down
9 changes: 3 additions & 6 deletions examples/async_reply_to_message_updates.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use frankenstein::AsyncTelegramApi;
use frankenstein::GetUpdatesParams;
use frankenstein::Message;
use frankenstein::ReplyParameters;
use frankenstein::SendMessageParams;
use frankenstein::{AsyncApi, UpdateContent};
use frankenstein::api_params::{GetUpdatesParams, ReplyParameters, SendMessageParams};
use frankenstein::objects::{Message, UpdateContent};
use frankenstein::{AsyncApi, AsyncTelegramApi};

static TOKEN: &str = "API_TOKEN";

Expand Down
4 changes: 2 additions & 2 deletions examples/custom_client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use frankenstein::Api;
use frankenstein::TelegramApi;
use std::time::Duration;

use frankenstein::{Api, TelegramApi};

static TOKEN: &str = "API_TOKEN";
static BASE_API_URL: &str = "https://api.telegram.org/bot";

Expand Down
3 changes: 1 addition & 2 deletions examples/get_me.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use frankenstein::Api;
use frankenstein::TelegramApi;
use frankenstein::{Api, TelegramApi};

static TOKEN: &str = "API_TOKEN";

Expand Down
9 changes: 3 additions & 6 deletions examples/inline_keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use frankenstein::Api;
use frankenstein::InlineKeyboardButton;
use frankenstein::InlineKeyboardMarkup;
use frankenstein::ReplyMarkup;
use frankenstein::SendMessageParams;
use frankenstein::TelegramApi;
use frankenstein::api_params::{ReplyMarkup, SendMessageParams};
use frankenstein::objects::{InlineKeyboardButton, InlineKeyboardMarkup};
use frankenstein::{Api, TelegramApi};

// replace with your token
static TOKEN: &str = "TOKEN";
Expand Down
9 changes: 3 additions & 6 deletions examples/reply_keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use frankenstein::Api;
use frankenstein::KeyboardButton;
use frankenstein::ReplyKeyboardMarkup;
use frankenstein::ReplyMarkup;
use frankenstein::SendMessageParams;
use frankenstein::TelegramApi;
use frankenstein::api_params::{ReplyMarkup, SendMessageParams};
use frankenstein::objects::{KeyboardButton, ReplyKeyboardMarkup};
use frankenstein::{Api, TelegramApi};

// replace with your token
static TOKEN: &str = "TOKEN";
Expand Down
8 changes: 3 additions & 5 deletions examples/reply_to_message_updates.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use frankenstein::GetUpdatesParams;
use frankenstein::ReplyParameters;
use frankenstein::SendMessageParams;
use frankenstein::TelegramApi;
use frankenstein::{Api, UpdateContent};
use frankenstein::api_params::{GetUpdatesParams, ReplyParameters, SendMessageParams};
use frankenstein::objects::UpdateContent;
use frankenstein::{Api, TelegramApi};

static TOKEN: &str = "API_TOKEN";

Expand Down
8 changes: 8 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md
format_code_in_doc_comments=true
format_macro_matchers=true
group_imports="StdExternalCrate"
imports_granularity="Module"
normalize_doc_attributes=true
reorder_impl_items=true
use_field_init_shorthand=true
9 changes: 5 additions & 4 deletions src/api_params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Parameters to Telegram API methods.
use std::path::PathBuf;

use bon::Builder;
use serde::{Deserialize, Serialize};

use crate::objects::{
AllowedUpdate, BotCommand, ChatAdministratorRights, ChatPermissions, ForceReply,
InlineKeyboardMarkup, InlineQueryResultArticle, InlineQueryResultAudio,
Expand All @@ -18,10 +23,6 @@ use crate::objects::{
WebAppInfo,
};
use crate::ParseMode;
use bon::Builder;
use serde::Deserialize;
use serde::Serialize;
use std::path::PathBuf;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
Expand Down
10 changes: 6 additions & 4 deletions src/client_reqwest.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::trait_async::AsyncTelegramApi;
use crate::Error;
use std::path::PathBuf;
use std::time::Duration;

use async_trait::async_trait;
use bon::Builder;
use reqwest::multipart;
use serde_json::Value;
use std::path::PathBuf;
use std::time::Duration;
use tokio::fs::File;

use crate::trait_async::AsyncTelegramApi;
use crate::Error;

/// Asynchronous [`AsyncTelegramApi`] client implementation with [`reqwest`].
#[derive(Debug, Clone, Builder)]
#[must_use = "API needs to be used in order to be useful"]
Expand Down
107 changes: 29 additions & 78 deletions src/client_ureq.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::trait_sync::TelegramApi;
use crate::Error;
use std::path::PathBuf;
use std::time::Duration;

use bon::Builder;
use multipart::client::lazy::Multipart;
use serde_json::Value;
use std::path::PathBuf;
use std::time::Duration;
use ureq::Response;

use crate::trait_sync::TelegramApi;
use crate::Error;

/// Synchronous [`TelegramApi`] client implementation with [`ureq`].
#[derive(Debug, Clone, Builder)]
#[must_use = "API needs to be used in order to be useful"]
Expand Down Expand Up @@ -142,80 +144,29 @@ impl TelegramApi for Api {
#[cfg(test)]
mod tests {
use super::*;
use crate::api_params::AnswerCallbackQueryParams;
use crate::api_params::AnswerInlineQueryParams;
use crate::api_params::BanChatMemberParams;
use crate::api_params::BotCommandScope;
use crate::api_params::BotCommandScopeChat;
use crate::api_params::ChatAction;
use crate::api_params::ChatId;
use crate::api_params::CopyMessageParams;
use crate::api_params::CreateChatInviteLinkParams;
use crate::api_params::DeleteChatPhotoParams;
use crate::api_params::DeleteChatStickerSetParams;
use crate::api_params::DeleteMessageParams;
use crate::api_params::DeleteMyCommandsParams;
use crate::api_params::DeleteWebhookParams;
use crate::api_params::EditChatInviteLinkParams;
use crate::api_params::EditMessageCaptionParams;
use crate::api_params::EditMessageLiveLocationParams;
use crate::api_params::EditMessageMediaParams;
use crate::api_params::EditMessageTextParams;
use crate::api_params::ExportChatInviteLinkParams;
use crate::api_params::FileUpload;
use crate::api_params::ForwardMessageParams;
use crate::api_params::GetChatAdministratorsParams;
use crate::api_params::GetChatMemberCountParams;
use crate::api_params::GetChatMemberParams;
use crate::api_params::GetChatParams;
use crate::api_params::GetFileParams;
use crate::api_params::GetMyCommandsParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserProfilePhotosParams;
use crate::api_params::InlineQueryResult;
use crate::api_params::InputFile;
use crate::api_params::InputMedia;
use crate::api_params::InputMediaPhoto;
use crate::api_params::LeaveChatParams;
use crate::api_params::Media;
use crate::api_params::PinChatMessageParams;
use crate::api_params::PromoteChatMemberParams;
use crate::api_params::RestrictChatMemberParams;
use crate::api_params::RevokeChatInviteLinkParams;
use crate::api_params::SendAnimationParams;
use crate::api_params::SendAudioParams;
use crate::api_params::SendChatActionParams;
use crate::api_params::SendContactParams;
use crate::api_params::SendDiceParams;
use crate::api_params::SendDocumentParams;
use crate::api_params::SendLocationParams;
use crate::api_params::SendMediaGroupParams;
use crate::api_params::SendMessageParams;
use crate::api_params::SendPhotoParams;
use crate::api_params::SendPollParams;
use crate::api_params::SendStickerParams;
use crate::api_params::SendVenueParams;
use crate::api_params::SendVideoNoteParams;
use crate::api_params::SendVideoParams;
use crate::api_params::SendVoiceParams;
use crate::api_params::SetChatAdministratorCustomTitleParams;
use crate::api_params::SetChatDescriptionParams;
use crate::api_params::SetChatPermissionsParams;
use crate::api_params::SetChatPhotoParams;
use crate::api_params::SetChatStickerSetParams;
use crate::api_params::SetChatTitleParams;
use crate::api_params::SetMyCommandsParams;
use crate::api_params::SetWebhookParams;
use crate::api_params::StopMessageLiveLocationParams;
use crate::api_params::StopPollParams;
use crate::api_params::UnbanChatMemberParams;
use crate::api_params::UnpinChatMessageParams;
use crate::objects::AllowedUpdate;
use crate::objects::BotCommand;
use crate::objects::ChatPermissions;
use crate::objects::InlineQueryResultVenue;
use crate::objects::InputPollOption;
use crate::api_params::{
AnswerCallbackQueryParams, AnswerInlineQueryParams, BanChatMemberParams, BotCommandScope,
BotCommandScopeChat, ChatAction, ChatId, CopyMessageParams, CreateChatInviteLinkParams,
DeleteChatPhotoParams, DeleteChatStickerSetParams, DeleteMessageParams,
DeleteMyCommandsParams, DeleteWebhookParams, EditChatInviteLinkParams,
EditMessageCaptionParams, EditMessageLiveLocationParams, EditMessageMediaParams,
EditMessageTextParams, ExportChatInviteLinkParams, FileUpload, ForwardMessageParams,
GetChatAdministratorsParams, GetChatMemberCountParams, GetChatMemberParams, GetChatParams,
GetFileParams, GetMyCommandsParams, GetStickerSetParams, GetUpdatesParams,
GetUserProfilePhotosParams, InlineQueryResult, InputFile, InputMedia, InputMediaPhoto,
LeaveChatParams, Media, PinChatMessageParams, PromoteChatMemberParams,
RestrictChatMemberParams, RevokeChatInviteLinkParams, SendAnimationParams, SendAudioParams,
SendChatActionParams, SendContactParams, SendDiceParams, SendDocumentParams,
SendLocationParams, SendMediaGroupParams, SendMessageParams, SendPhotoParams,
SendPollParams, SendStickerParams, SendVenueParams, SendVideoNoteParams, SendVideoParams,
SendVoiceParams, SetChatAdministratorCustomTitleParams, SetChatDescriptionParams,
SetChatPermissionsParams, SetChatPhotoParams, SetChatStickerSetParams, SetChatTitleParams,
SetMyCommandsParams, SetWebhookParams, StopMessageLiveLocationParams, StopPollParams,
UnbanChatMemberParams, UnpinChatMessageParams,
};
use crate::objects::{
AllowedUpdate, BotCommand, ChatPermissions, InlineQueryResultVenue, InputPollOption,
};
use crate::response::ErrorResponse;

#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::response::ErrorResponse;
use serde::{Deserialize, Serialize};

use crate::response::ErrorResponse;

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
#[serde(untagged)]
Expand Down
Loading

0 comments on commit 242304b

Please sign in to comment.