Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints #743

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/octocrab"
categories = ["web-programming::http-client"]
keywords = ["github", "github-api"]
rust-version = "1.73.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[package.metadata.docs.rs]
Expand All @@ -24,11 +25,7 @@ async-trait = "0.1.50"
arc-swap = "1.3.0"
base64 = "0.22.0"
bytes = "1.0.1"
chrono = { version = "0.4.19", default-features = false, features = [
"serde",
"clock",
"wasmbind"
] }
chrono = { version = "0.4.19", default-features = false, features = ["serde", "clock", "wasmbind"] }
web-time = { version = "1.1.0", features = ["serde"] }
cfg-if = "1.0.0"
either = "1.8.0"
Expand All @@ -42,10 +39,10 @@ http-body-util = "0.1.0"
hyper = "1.1.0"
hyper-rustls = { version = "0.27.0", optional = true, default-features = false, features = [
"http1",
"logging",
"native-tokio",
"tls12",
]}
"logging",
"native-tokio",
"tls12",
] }
hyper-timeout = { version = "0.5.1", optional = true }
hyper-tls = { version = "0.6.0", optional = true }
hyper-util = { version = "0.1.3", features = ["http1"] }
Expand Down Expand Up @@ -78,7 +75,15 @@ pretty_assertions = "1.4.0"
graphql_client = "0.14.0"

[features]
default = ["follow-redirect", "retry", "rustls", "timeout", "tracing", "default-client", "rustls-ring"]
default = [
"follow-redirect",
"retry",
"rustls",
"timeout",
"tracing",
"default-client",
"rustls-ring",
]

follow-redirect = ["tower-http/follow-redirect"]
retry = ["tower/retry", "futures-util"]
Expand Down
1 change: 1 addition & 0 deletions examples/graphql_issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! ```
use graphql_client::GraphQLQuery;

#[allow(clippy::upper_case_acronyms)]
type URI = String;

#[derive(GraphQLQuery)]
Expand Down
2 changes: 1 addition & 1 deletion src/api/code_scannings/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct ListCodeScanningsBuilder<'octo, 'b> {
severity: Option<params::code_scannings::Severity>,
}

impl<'octo, 'b, 'c, 'd> ListCodeScanningsBuilder<'octo, 'b> {
impl<'octo, 'b> ListCodeScanningsBuilder<'octo, 'b> {
pub(crate) fn new(handler: &'b CodeScanningHandler<'octo>) -> Self {
Self {
handler,
Expand Down
2 changes: 1 addition & 1 deletion src/api/code_scannings/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct UpdateCodeScanningBuilder<'octo, 'a> {
dismissed_comment: Option<String>,
}

impl<'octo, 'a, 'b, 'c> UpdateCodeScanningBuilder<'octo, 'a> {
impl<'octo, 'a> UpdateCodeScanningBuilder<'octo, 'a> {
pub(crate) fn new(handler: &'a CodeScanningHandler<'octo>, number: u64) -> Self {
Self {
handler,
Expand Down
4 changes: 2 additions & 2 deletions src/api/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ impl<'octo, 'r> ListTimelineEventsBuilder<'octo, 'r> {
}

// Timeline
impl<'octo> IssueHandler<'octo> {
impl IssueHandler<'_> {
/// Lists events in the issue timeline.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
Expand All @@ -800,7 +800,7 @@ impl<'octo> IssueHandler<'octo> {
}
}

impl<'octo> IssueHandler<'octo> {
impl IssueHandler<'_> {
/// Lists reactions for an issue.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
Expand Down
1 change: 0 additions & 1 deletion src/api/orgs/secrets.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use http::StatusCode;
use snafu::GenerateImplicitData;

use super::OrgHandler;
use crate::models::orgs::secrets::{CreateOrganizationSecret, CreateOrganizationSecretResponse};
Expand Down
1 change: 1 addition & 0 deletions src/api/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! # Notes
//! Users need an account with sufficient privileges to interact with projects.

#[allow(clippy::module_inception)]
mod projects;

use self::projects::{
Expand Down
2 changes: 1 addition & 1 deletion src/api/repos/forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'octo, 'r> CreateForkBuilder<'octo, 'r> {
}
}

impl<'octo> RepoHandler<'octo> {
impl RepoHandler<'_> {
/// List forks of a repository. Optionally, specify the
/// [sort](ListForksBuilder::sort()) order,
/// [page](ListForksBuilder::page()),
Expand Down
2 changes: 1 addition & 1 deletion src/api/repos/release_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct UpdateReleaseAssetBuilder<'octo, 'repos, 'handler, 'name, 'label> {
state: Option<crate::params::repos::release_assets::State>,
}

impl<'octo, 'repos, 'handler, 'name, 'label, 'state>
impl<'octo, 'repos, 'handler, 'name, 'label>
UpdateReleaseAssetBuilder<'octo, 'repos, 'handler, 'name, 'label>
{
pub(crate) fn new(
Expand Down
1 change: 0 additions & 1 deletion src/api/repos/secrets.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use http::StatusCode;
use snafu::GenerateImplicitData;

use super::RepoHandler;
use crate::models::repos::secrets::{CreateRepositorySecret, CreateRepositorySecretResponse};
Expand Down
5 changes: 2 additions & 3 deletions src/api/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::backtrace::Backtrace;

use http::StatusCode;
use snafu::GenerateImplicitData;

pub use self::follow::{ListUserFollowerBuilder, ListUserFollowingBuilder};
use self::user_repos::ListUserReposBuilder;
Expand Down Expand Up @@ -120,12 +119,12 @@ impl<'octo> UserHandler<'octo> {
let result: crate::Result<()> = self.crab.put(route, None::<&()>).await;
match result {
Ok(_) => Err(error::Error::GitHub {
source: GitHubError {
source: Box::new(GitHubError {
status_code: StatusCode::OK,
documentation_url: None,
errors: None,
message: "".to_string(),
},
}),
backtrace: Backtrace::capture(),
}),
Err(_v) => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use http_body_util::BodyExt;

use bytes::Bytes;
use http_body::Frame;
use snafu::{Backtrace, GenerateImplicitData};
use snafu::Backtrace;
use std::pin::Pin;
use std::sync::{Arc, RwLock};
use std::task::{Context, Poll};
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl std::error::Error for UriParseError {}
#[non_exhaustive]
pub enum Error {
GitHub {
source: GitHubError,
source: Box<GitHubError>,
backtrace: Backtrace,
},
UriParse {
Expand Down
1 change: 0 additions & 1 deletion src/etag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};

use http::header::{HeaderMap, InvalidHeaderValue};
use snafu::GenerateImplicitData;

/// Represents resources identified by etags.
#[derive(Debug, PartialEq)]
Expand Down
22 changes: 9 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ pub async fn map_github_error(
.context(error::SerdeSnafu)?;

Err(error::Error::GitHub {
source: GitHubError {
source: Box::new(GitHubError {
status_code: parts.status,
documentation_url,
errors,
message,
},
}),
backtrace: Backtrace::capture(),
})
}
Expand Down Expand Up @@ -365,8 +365,11 @@ pub fn instance() -> Arc<Octocrab> {
STATIC_INSTANCE.load().clone()
}

type Executor = Box<dyn Fn(Pin<Box<dyn Future<Output = ()>>>)>;

/// A builder struct for `Octocrab`, allowing you to configure the client, such
/// as using GitHub previews, the github instance, authentication, etc.
///
/// ```
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -377,17 +380,14 @@ pub fn instance() -> Arc<Octocrab> {
/// # Ok(())
/// # }
/// ```

//Typed builder, thanks to https://www.greyblake.com/blog/builder-with-typestate-in-rust/ for explaining

/// A builder struct for `Octocrab`.
///
/// OctocrabBuilder can be extended with a custom config, see [DefaultOctocrabBuilderConfig] for an example
pub struct OctocrabBuilder<Svc, Config, Auth, LayerReady> {
service: Svc,
auth: Auth,
config: Config,
_layer_ready: PhantomData<LayerReady>,
executor: Option<Box<dyn Fn(Pin<Box<dyn Future<Output = ()>>>) -> ()>>,
executor: Option<Executor>,
}

//Indicates weather the builder supports config
Expand Down Expand Up @@ -443,7 +443,7 @@ where
{
pub fn with_executor(
self,
executor: Box<dyn Fn(Pin<Box<dyn Future<Output = ()>>>) -> ()>,
executor: Executor,
) -> OctocrabBuilder<Svc, Config, Auth, LayerReady> {
OctocrabBuilder {
service: self.service,
Expand Down Expand Up @@ -1043,11 +1043,7 @@ impl Octocrab {
}

/// Creates a new `Octocrab` with a custom executor
fn new_with_executor<S>(
service: S,
auth_state: AuthState,
executor: Box<dyn Fn(Pin<Box<dyn Future<Output = ()>>>) -> ()>,
) -> Self
fn new_with_executor<S>(service: S, auth_state: AuthState, executor: Executor) -> Self
where
S: Service<Request<OctoBody>, Response = Response<BoxBody<Bytes, crate::Error>>>
+ Send
Expand Down
2 changes: 1 addition & 1 deletion src/models/date_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where

struct GithubTimestampVisitor;

impl<'de> de::Visitor<'de> for GithubTimestampVisitor {
impl de::Visitor<'_> for GithubTimestampVisitor {
type Value = DateTime<Utc>;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions src/models/pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl<'de> Deserialize<'de> for ReviewState {
{
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = ReviewState;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -391,7 +391,7 @@ impl<'de> Deserialize<'de> for Side {
{
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = Side;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::slice::Iter;
use std::str::FromStr;

use crate::error::{SerdeSnafu, UriSnafu};
use snafu::{GenerateImplicitData, ResultExt};
use snafu::ResultExt;
use url::form_urlencoded;

cfg_if::cfg_if! {
Expand Down
Loading