From 400a6da7a0394180d847c890d728c56b8c37f859 Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Thu, 22 Aug 2024 17:21:16 -0700 Subject: [PATCH] cleanup --- ic-agent/src/agent/agent_config.rs | 2 +- ic-agent/src/agent/agent_error.rs | 2 +- ic-agent/src/agent/agent_test.rs | 2 -- ic-agent/src/agent/builder.rs | 3 +-- ic-agent/src/agent/http_transport/mod.rs | 2 +- ic-agent/src/agent/http_transport/reqwest_transport.rs | 10 +++++----- ic-agent/src/agent/mod.rs | 10 +++++----- ic-identity-hsm/src/lib.rs | 4 ++-- ic-utils/src/lib.rs | 2 +- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/ic-agent/src/agent/agent_config.rs b/ic-agent/src/agent/agent_config.rs index 0c72a927..54bd51df 100644 --- a/ic-agent/src/agent/agent_config.rs +++ b/ic-agent/src/agent/agent_config.rs @@ -16,7 +16,7 @@ pub struct AgentConfig { pub identity: Arc, /// See [`with_ingress_expiry`](super::AgentBuilder::with_ingress_expiry). pub ingress_expiry: Option, - /// See [`with_client`](super::AgentBuilder::with_client). + /// See [`with_http_client`](super::AgentBuilder::with_http_client). pub client: Option, /// See [`with_route_provider`](super::AgentBuilder::with_route_provider). pub route_provider: Option>, diff --git a/ic-agent/src/agent/agent_error.rs b/ic-agent/src/agent/agent_error.rs index 482ce90c..b346c537 100644 --- a/ic-agent/src/agent/agent_error.rs +++ b/ic-agent/src/agent/agent_error.rs @@ -181,7 +181,7 @@ pub enum AgentError { /// An unknown error occurred during communication with the replica. #[error("An error happened during communication with the replica: {0}")] - TransportError(Box), + TransportError(#[from] reqwest::Error), /// There was a mismatch between the expected and actual CBOR data during inspection. #[error("There is a mismatch between the CBOR encoded call and the arguments: field {field}, value in argument is {value_arg}, value in CBOR is {value_cbor}")] diff --git a/ic-agent/src/agent/agent_test.rs b/ic-agent/src/agent/agent_test.rs index 82c5f322..227c4672 100644 --- a/ic-agent/src/agent/agent_test.rs +++ b/ic-agent/src/agent/agent_test.rs @@ -1,5 +1,3 @@ -// Disable these tests without the reqwest feature. - use self::mock::{ assert_mock, assert_single_mock, assert_single_mock_count, mock, mock_additional, }; diff --git a/ic-agent/src/agent/builder.rs b/ic-agent/src/agent/builder.rs index 660b81e5..7fbc8559 100644 --- a/ic-agent/src/agent/builder.rs +++ b/ic-agent/src/agent/builder.rs @@ -60,8 +60,7 @@ impl AgentBuilder { self.with_arc_identity(Arc::from(identity)) } - /// Same as [`Self::with_identity`], but provides a `Arc` boxed implementation instead - /// of a direct type. + /// Same as [`Self::with_identity`], but reuses an existing `Arc` pub fn with_arc_identity(mut self, identity: Arc) -> Self { self.config.identity = identity; self diff --git a/ic-agent/src/agent/http_transport/mod.rs b/ic-agent/src/agent/http_transport/mod.rs index 33434db8..bf937667 100644 --- a/ic-agent/src/agent/http_transport/mod.rs +++ b/ic-agent/src/agent/http_transport/mod.rs @@ -1,4 +1,4 @@ -//! This module has been removed in favor of builder methods on `AgentBuilder`. +//! This module has been deprecated in favor of builder methods on `AgentBuilder`. #[deprecated(since = "0.38.0", note = "use the AgentBuilder methods")] #[doc(hidden)] diff --git a/ic-agent/src/agent/http_transport/reqwest_transport.rs b/ic-agent/src/agent/http_transport/reqwest_transport.rs index 2aa37344..2ce36791 100644 --- a/ic-agent/src/agent/http_transport/reqwest_transport.rs +++ b/ic-agent/src/agent/http_transport/reqwest_transport.rs @@ -1,4 +1,4 @@ -//! A [`Transport`] that connects using a [`reqwest`] client. +//! This module has been deprecated in favor of builder methods on `AgentBuilder`. #![allow(deprecated)] pub use reqwest; use std::{sync::Arc, time::Duration}; @@ -45,20 +45,20 @@ impl ReqwestTransport { } } - /// Equivalent to [`AgentBuilder::with_url`] and [`AgentBuilder::with_client`]. + /// Equivalent to [`AgentBuilder::with_url`] and [`AgentBuilder::with_http_client`]. #[deprecated( since = "0.38.0", - note = "Use AgentBuilder::with_url and AgentBuilder::with_client" + note = "Use AgentBuilder::with_url and AgentBuilder::with_http_client" )] pub fn create_with_client>(url: U, client: Client) -> Result { let route_provider = Arc::new(RoundRobinRouteProvider::new(vec![url.into()])?); Self::create_with_client_route(route_provider, client) } - /// Equivalent to [`AgentBuilder::with_client`] and [`AgentBuilder::with_route_provider`]. + /// Equivalent to [`AgentBuilder::with_http_client`] and [`AgentBuilder::with_route_provider`]. #[deprecated( since = "0.38.0", - note = "Use AgentBuilder::with_client and AgentBuilder::with_arc_route_provider" + note = "Use AgentBuilder::with_http_client and AgentBuilder::with_arc_route_provider" )] pub fn create_with_client_route( route_provider: Arc, diff --git a/ic-agent/src/agent/mod.rs b/ic-agent/src/agent/mod.rs index 32a96acf..9fb4d400 100644 --- a/ic-agent/src/agent/mod.rs +++ b/ic-agent/src/agent/mod.rs @@ -219,7 +219,7 @@ impl Agent { /// Set the identity provider for signing messages. /// /// NOTE: if you change the identity while having update calls in - /// flight, you will not be able to [Agent::poll] the status of these + /// flight, you will not be able to [`Agent::request_status_raw`] the status of these /// messages. pub fn set_identity(&mut self, identity: I) where @@ -230,7 +230,7 @@ impl Agent { /// Set the arc identity provider for signing messages. /// /// NOTE: if you change the identity while having update calls in - /// flight, you will not be able to [Agent::poll] the status of these + /// flight, you will not be able to [`Agent::request_status_raw`] the status of these /// messages. pub fn set_arc_identity(&mut self, identity: Arc) { self.identity = identity; @@ -1165,12 +1165,12 @@ impl Agent { // Network-related errors can be retried. if err.is_connect() { if retry_count >= self.max_tcp_error_retries { - return Err(AgentError::TransportError(Box::new(err))); + return Err(AgentError::TransportError(err)); } retry_count += 1; continue; } - return Err(AgentError::TransportError(Box::new(err))); + return Err(AgentError::TransportError(err)); } } } @@ -1195,7 +1195,7 @@ impl Agent { let mut stream = response.bytes_stream(); while let Some(chunk) = stream.next().await { - let chunk = chunk.map_err(|x| AgentError::TransportError(Box::new(x)))?; + let chunk = chunk?; // Size Check (Body Size) if matches!(self diff --git a/ic-identity-hsm/src/lib.rs b/ic-identity-hsm/src/lib.rs index 51d25203..3d0c7ef3 100644 --- a/ic-identity-hsm/src/lib.rs +++ b/ic-identity-hsm/src/lib.rs @@ -5,7 +5,7 @@ //! # Example //! //! ```rust,no_run -//! use ic_agent::agent::{Agent, http_transport::ReqwestTransport}; +//! use ic_agent::agent::Agent; //! use ic_identity_hsm::HardwareIdentity; //! # fn main() -> Result<(), Box> { //! # let replica_url = ""; @@ -13,7 +13,7 @@ //! # let slot_index = 0; //! # let key_id = ""; //! let agent = Agent::builder() -//! .with_transport(ReqwestTransport::create(replica_url)?) +//! .with_url(replica_url) //! .with_identity(HardwareIdentity::new(lib_path, slot_index, key_id, || Ok("hunter2".to_string()))?) //! .build(); //! # Ok(()) diff --git a/ic-utils/src/lib.rs b/ic-utils/src/lib.rs index 85b27ca3..2f7e70cc 100644 --- a/ic-utils/src/lib.rs +++ b/ic-utils/src/lib.rs @@ -15,7 +15,7 @@ pub mod call; /// A higher-level canister type for managing various aspects of a canister. pub mod canister; -/// A few known canister types for use with [`Canister`](canister::Canister). +/// A few known canister types for use with [`Canister`]. pub mod interfaces; pub use canister::{Argument, Canister};