Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed Oct 6, 2023
1 parent c6a06d5 commit 9479165
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
25 changes: 11 additions & 14 deletions cargo-registry/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ pub struct ClientConfig<'a>(pub ProgramV4CommandConfig<'a>);

impl<'a> ClientConfig<'a> {
pub fn new(client: &'a Client) -> Self {
Self {
0: ProgramV4CommandConfig {
websocket_url: &client.websocket_url,
commitment: client.commitment,
payer: &client.cli_signers[0],
authority: &client.cli_signers[client.authority_signer_index],
output_format: &OutputFormat::Display,
use_quic: true,
},
}
Self(ProgramV4CommandConfig {
websocket_url: &client.websocket_url,
commitment: client.commitment,
payer: &client.cli_signers[0],
authority: &client.cli_signers[client.authority_signer_index],
output_format: &OutputFormat::Display,
use_quic: true,
})
}
}

Expand All @@ -56,7 +54,7 @@ impl Client {
config_path,
);

let default_signer = DefaultSigner::new(name, &default_signer_path);
let default_signer = DefaultSigner::new(name, default_signer_path);

read_keypair_file(default_signer.path)
}
Expand Down Expand Up @@ -189,9 +187,8 @@ impl Client {
let confirm_transaction_initial_timeout =
Duration::from_secs(confirm_transaction_initial_timeout);

let payer_keypair = Self::get_keypair(&matches, &config.keypair_path, "keypair".as_ref())?;
let authority_keypair =
Self::get_keypair(&matches, &config.keypair_path, "authority".as_ref())?;
let payer_keypair = Self::get_keypair(&matches, &config.keypair_path, "keypair")?;
let authority_keypair = Self::get_keypair(&matches, &config.keypair_path, "authority")?;

let port = value_t_or_exit!(matches, "port", u16);

Expand Down
20 changes: 10 additions & 10 deletions cargo-registry/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ impl CargoRegistryService {
fn error_response() -> hyper::Response<hyper::Body> {
hyper::Response::builder()
.status(hyper::StatusCode::OK)
.body(hyper::Body::from(format!("{}", "error")))
.body(hyper::Body::from("error"))
.unwrap()
}

fn success_response() -> hyper::Response<hyper::Body> {
hyper::Response::builder()
.status(hyper::StatusCode::OK)
.body(hyper::Body::from(format!("{}", "success")))
.body(hyper::Body::from("success"))
.unwrap()
}

Expand All @@ -51,9 +51,9 @@ impl CargoRegistryService {
}

fn get_crate_name_and_version(path: &str) -> Option<(&str, &str, &str)> {
path.rsplit_once("/").and_then(|(remainder, version)| {
path.rsplit_once('/').and_then(|(remainder, version)| {
remainder
.rsplit_once("/")
.rsplit_once('/')
.map(|(remainder, name)| (remainder, name, version))
})
}
Expand Down Expand Up @@ -89,7 +89,7 @@ impl CargoRegistryService {
}

fn get_crate_name(path: &str) -> Option<(&str, &str)> {
path.rsplit_once("/")
path.rsplit_once('/')
}

fn handle_get_owners_request(
Expand Down Expand Up @@ -169,12 +169,12 @@ impl CargoRegistryService {
return Ok(Self::error_response());
}

let Some((path, endpoint)) = path.rsplit_once("/") else {
let Some((path, endpoint)) = path.rsplit_once('/') else {
return Ok(Self::error_response());
};

Ok(match request.method() {
&Method::PUT => match endpoint {
Ok(match *request.method() {
Method::PUT => match endpoint {
"new" => {
if path.len() != PATH_PREFIX.len() {
Self::error_response()
Expand All @@ -186,12 +186,12 @@ impl CargoRegistryService {
"owners" => Self::handle_add_owners_request(path, &request),
_ => Self::error_response(),
},
&Method::GET => match endpoint {
Method::GET => match endpoint {
"crates" => Self::handle_get_crates_request(path, &request),
"owners" => Self::handle_get_owners_request(path, &request),
_ => Self::error_response(),
},
&Method::DELETE => match endpoint {
Method::DELETE => match endpoint {
"yank" => Self::handle_yank_request(path, &request),
"owners" => Self::handle_delete_owners_request(path, &request),
_ => Self::error_response(),
Expand Down
2 changes: 1 addition & 1 deletion cargo-registry/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl PackageMetaData {
let (json_length, sizeof_length) = Self::read_u32_length(bytes)?;
let end_of_meta_data = sizeof_length.saturating_add(json_length as usize);
let json_body = bytes.slice(sizeof_length..end_of_meta_data);
from_slice::<PackageMetaData>(&json_body.deref()).map(|data| (data, end_of_meta_data))
from_slice::<PackageMetaData>(json_body.deref()).map(|data| (data, end_of_meta_data))
}

fn read_u32_length(bytes: &Bytes) -> serde_json::Result<(u32, usize)> {
Expand Down

0 comments on commit 9479165

Please sign in to comment.