From 9572865c99d4ccd1c9c88cfc7f3b15f1eb00a486 Mon Sep 17 00:00:00 2001 From: Benedikt Schnatterbeck Date: Tue, 16 Jul 2024 19:09:00 +0100 Subject: [PATCH] chore: enable various clippy warnings --- src/api_configs/associations.rs | 4 ++-- src/api_configs/batch.rs | 21 ++++++++++----------- src/api_configs/mod.rs | 14 ++++++-------- src/api_configs/query.rs | 16 ++++++++-------- src/api_configs/types.rs | 33 ++++++++++++++++++++------------- src/builder.rs | 12 ++++++------ src/client/mod.rs | 3 ++- src/engagements/mod.rs | 2 +- src/engagements/notes.rs | 1 + src/lib.rs | 20 ++++++++++++++++++++ src/objects.rs | 6 +++--- src/owners.rs | 12 ++++++------ 12 files changed, 85 insertions(+), 59 deletions(-) diff --git a/src/api_configs/associations.rs b/src/api_configs/associations.rs index c1dfa4a..6748f91 100644 --- a/src/api_configs/associations.rs +++ b/src/api_configs/associations.rs @@ -36,7 +36,7 @@ pub struct AssociationTypes { /// A struct for creating new associations. #[derive(Serialize, Debug)] pub struct AssociationCreationDetails { - /// Whether the association type was created by HubSpot or a user (HUBSPOT_DEFINED and USER_DEFINED) + /// Whether the association type was created by `HubSpot` or a user (`HUBSPOT_DEFINED` an`USER_DEFINED`ED) #[serde(rename = "associationCategory")] pub category: String, /// The numeric ID for that association type. @@ -81,7 +81,7 @@ impl AssociationsApiCollection where T: ToPath, { - /// Constructs a new AssociationsApiCollection for an object type. + /// Constructs a new `AssociationsApiCollection` for an object type. pub fn new(name: T, client: Arc) -> Self { Self(name, client) } diff --git a/src/api_configs/batch.rs b/src/api_configs/batch.rs index eb9fa73..c9a8483 100644 --- a/src/api_configs/batch.rs +++ b/src/api_configs/batch.rs @@ -15,8 +15,8 @@ struct BatchInputs { } impl BatchInputs { - /// Constructs a new BatchInput - pub fn new(inputs: Vec) -> BatchInputs { + /// Constructs a new `BatchInput` + fn new(inputs: Vec) -> BatchInputs { BatchInputs { inputs } } } @@ -32,19 +32,16 @@ struct BatchUpdateInput { } impl BatchUpdateInput { - /// Constructs a new BatchUpdateInput - pub fn new(id: &str, properties: Properties) -> BatchUpdateInput { + /// Constructs a new `BatchUpdateInput` + fn new(id: &str, properties: Properties) -> BatchUpdateInput { BatchUpdateInput { id: id.to_string(), properties, } } - /// Constructs a new vec of BatchUpdateInputs from a list of record IDs. - pub fn new_batch( - ids: Vec, - properties: Properties, - ) -> Vec> { + /// Constructs a new vec of `BatchUpdateInputs` from a list of record IDs. + fn new_batch(ids: Vec, properties: Properties) -> Vec> { ids.iter() .map(|id| BatchUpdateInput::new(id, properties.clone())) .collect() @@ -128,7 +125,7 @@ impl BatchApiCollection where T: ToPath, { - /// Constructs a new BatchApiCollection for a Hubspot Object + /// Constructs a new `BatchApiCollection` for a Hubspot Object pub fn new(name: T, client: Arc) -> Self { Self(name, client) } @@ -145,7 +142,9 @@ where .json::>(&BatchInputs:: { inputs: ids .iter() - .map(|i| BatchIdInput { id: i.to_string() }) + .map(|i| BatchIdInput { + id: (*i).to_string(), + }) .collect(), }), ) diff --git a/src/api_configs/mod.rs b/src/api_configs/mod.rs index 6044f92..df97499 100644 --- a/src/api_configs/mod.rs +++ b/src/api_configs/mod.rs @@ -1,15 +1,13 @@ mod associations; mod batch; -pub mod query; +pub(crate) mod query; pub mod types; use std::sync::Arc; pub use associations::{AssociationCreationDetails, AssociationTypes}; -pub use types::{ - AssociationLinks, AssociationType, CreateAssociation, HubspotRecord, OptionNotDesired, -}; +pub(crate) use types::{CreateAssociation, HubspotRecord, OptionNotDesired}; use crate::client::HubspotClient; @@ -69,7 +67,7 @@ where /// Properties: A struct of the properties to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. /// - /// PropertiesWithHistory: A struct of the properties with history to be returned in the response. + /// `PropertiesWithHistory`: A struct of the properties with history to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. /// /// Associations: A struct of the associations to be returned in the response. @@ -113,7 +111,7 @@ where /// Properties: A struct of the properties to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. /// - /// PropertiesWithHistory: A struct of the properties with history to be returned in the response. + /// `PropertiesWithHistory`: A struct of the properties with history to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. /// /// Associations: A struct of the associations to be returned in the response. @@ -143,7 +141,7 @@ where /// Properties: A struct of the properties to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. /// - /// PropertiesWithHistory: A struct of the properties with history to be returned in the response. + /// `PropertiesWithHistory`: A struct of the properties with history to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. /// /// Associations: A struct of the associations to be returned in the response. @@ -184,7 +182,7 @@ where /// Properties: A struct of the properties to be updated and returned in the response. /// If the requested object doesn't have a value for a property, it will not be updated or appear in the response. /// - /// PropertiesWithHistory: A struct of the properties with history to be returned in the response. + /// `PropertiesWithHistory`: A struct of the properties with history to be returned in the response. /// If the requested object doesn't have a value for a property, it will not appear in the response. pub async fn update( &self, diff --git a/src/api_configs/query.rs b/src/api_configs/query.rs index b5f62d3..a1ce54e 100644 --- a/src/api_configs/query.rs +++ b/src/api_configs/query.rs @@ -1,5 +1,5 @@ /// Check if query has begun. -pub fn query_begun_check(checkpoint: bool) -> (String, bool) { +fn query_begun_check(checkpoint: bool) -> (String, bool) { if checkpoint { ("&".to_string(), checkpoint) } else { @@ -8,13 +8,13 @@ pub fn query_begun_check(checkpoint: bool) -> (String, bool) { } /// Build the query for hubspot paging. -pub fn build_paging_query(limit: Option, after: Option<&str>) -> (String, bool) { +pub(crate) fn build_paging_query(limit: Option, after: Option<&str>) -> (String, bool) { let mut query_begun = false; let limit_query = match limit { Some(limit) => { query_begun = true; - format!("?limit={}", limit) + format!("?limit={limit}") } None => String::new(), }; @@ -28,11 +28,11 @@ pub fn build_paging_query(limit: Option, after: Option<&str>) -> (String, b None => String::new(), }; - (format!("{}{}", limit_query, after_query), query_begun) + (format!("{limit_query}{after_query}"), query_begun) } -/// Build a query string from properties, properties_with_history, associations, and archived -pub fn build_query_string( +/// Build a query string from properties, `properties_with_history`, associations, and archived +pub(crate) fn build_query_string( query_already_begun: bool, properties: &[&str], properties_with_history: &[&str], @@ -67,9 +67,9 @@ pub fn build_query_string( format!("{}associations={}", query_check.0, associations.join(",")) }; let archived_query = if query_begun { - format!("&archived={}", archived) + format!("&archived={archived}") } else { - format!("?archived={}", archived) + format!("?archived={archived}") }; format!("{property_query}{properties_with_history_query}{associations_query}{archived_query}") diff --git a/src/api_configs/types.rs b/src/api_configs/types.rs index a9165fd..25c0992 100644 --- a/src/api_configs/types.rs +++ b/src/api_configs/types.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::client::HubspotClient; -/// ToPath trait represents a Hubspot object's path. +/// `ToPath` trait represents a Hubspot object's path. pub trait ToPath { /// Returns the object's path for the api routes. fn to_path(&self) -> String; @@ -53,9 +53,9 @@ pub struct HubspotRecord { pub archived_at: Option, } -/// Implementation of HubspotRecord where only Properties are required. +/// Implementation of `HubspotRecord` where only Properties are required. impl HubspotRecord { - /// Create a new HubspotRecord with the given properties and default values for all other fields. + /// Create a new `HubspotRecord` with the given properties and default values for all other fields. /// Suggested use for the Core Update endpoint. pub fn with_properties( properties: Properties, @@ -73,10 +73,10 @@ impl HubspotRecord { } } -/// Implementation of HubspotRecord where Properties and AssociationsToCreate are required. +/// Implementation of `HubspotRecord` where Properties and `AssociationsToCreate` are required. /// Recommended use for the base create endpoint. impl HubspotRecord> { - /// Create a new HubspotRecord with the given properties. Initializes a vec for associations to create. Default values for all other fields. + /// Create a new `HubspotRecord` with the given properties. Initializes a vec for associations to create. Default values for all other fields. /// Suggested use for the Core New endpoint. pub fn with_properties_and_associations( properties: Properties, @@ -94,6 +94,7 @@ impl HubspotRecord HubspotRecord Self { for id in ids { self.associations - .push(CreateAssociation::new_built_in(id, &association_type)) + .push(CreateAssociation::new_built_in(id, &association_type)); } self } /// Attach multiple associations of the same custom association type + #[must_use] pub fn attach_associations( mut self, association_type: AssociationType, @@ -114,7 +116,7 @@ impl HubspotRecord Self { for id in ids { self.associations - .push(CreateAssociation::new(id, &association_type)) + .push(CreateAssociation::new(id, &association_type)); } self } @@ -190,15 +192,17 @@ pub struct PagingNext { /// An enum of Built In Hubspot Associations. /// To be built upon in the future. +#[derive(Debug)] pub enum AssociationLinks { NoteToContact, NoteToCompany, NoteToDeal, } -/// Implementation of CreateAssociation +/// Implementation of `CreateAssociation` impl CreateAssociation { - /// Create a new association using the AssociationLinks + /// Create a new association using the `AssociationLinks` + #[must_use] pub fn new_built_in(id: String, association_type: &AssociationLinks) -> Self { Self { to: AssociationTo { id }, @@ -206,6 +210,7 @@ impl CreateAssociation { } } + #[must_use] pub fn new(id: String, association_type: &AssociationType) -> Self { Self { to: AssociationTo { id }, @@ -214,9 +219,10 @@ impl CreateAssociation { } } -/// Implementation of AssociationLinks +/// Implementation of `AssociationLinks` impl AssociationLinks { - /// Build a new AssociationType from the given AssociationLinks + /// Build a new `AssociationType` from the give`AssociationLinks`ks + #[must_use] pub fn build(&self) -> AssociationType { AssociationType { id: match self { @@ -229,9 +235,10 @@ impl AssociationLinks { } } -/// Implementation of AssociationType +/// Implementation of `AssociationType` impl AssociationType { - /// Constructs a new AssociationType + /// Constructs a new `AssociationType` + #[must_use] pub fn new(id: &str, category: &str) -> Self { Self { id: id.to_string(), diff --git a/src/builder.rs b/src/builder.rs index 3de329b..2bc35d7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -8,7 +8,7 @@ use crate::Hubspot; use super::client::HubspotClient; /// Hubspot api interface. -#[derive(Default)] +#[derive(Default, Debug)] pub struct HubspotBuilder { client: Option, domain: Option, @@ -17,9 +17,9 @@ pub struct HubspotBuilder { } impl HubspotBuilder { - /// Create an instance of the HubSpot API builder. + /// Create an instance of the `HubSpot` API builder. pub fn new() -> Self { - Default::default() + HubspotBuilder::default() } /// Build the Hubspot API Library. @@ -77,11 +77,11 @@ impl HubspotBuilder { #[allow(clippy::enum_variant_names)] #[derive(Debug, PartialOrd, PartialEq)] pub enum HubspotBuilderError { - /// Indicates builder didn't set [HubspotBuilder::domain]. + /// Indicates builder didn't set [`HubspotBuilder::domain`]. MissingDomain, - /// Indicates builder didn't set [HubspotBuilder::token]. + /// Indicates builder didn't set [`HubspotBuilder::token`]. MissingToken, - /// Indicates builder didn't set [HubspotBuilder::portal_id]. + /// Indicates builder didn't set [`HubspotBuilder::portal_id`]. MissingPortalId, } diff --git a/src/client/mod.rs b/src/client/mod.rs index b99e17c..d5a38ea 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -17,7 +17,8 @@ pub struct HubspotClient { } impl HubspotClient { - /// Create HubspotClient + /// Create `HubspotClient` + #[must_use] pub fn new(client: Client, domain: &str, token: &str, portal_id: &str) -> Self { Self { client, diff --git a/src/engagements/mod.rs b/src/engagements/mod.rs index 4f9d6d0..9cec758 100644 --- a/src/engagements/mod.rs +++ b/src/engagements/mod.rs @@ -24,7 +24,7 @@ impl ToPath for EngagementType { /// For example, if you call a prospect, you can log a call to the contact record, /// and also associate the call with their associated company. /// Possible activities include notes, tasks, meetings, emails, calls, postal mail, -/// SMS, LinkedIn messages, and WhatsApp messaged. +/// SMS, `LinkedIn` messages, an`WhatsApp`pp messaged. #[derive(Clone, Debug)] pub struct EngagementsManager { /// Notes add information to the record timeline. diff --git a/src/engagements/notes.rs b/src/engagements/notes.rs index 99ffaff..643d366 100644 --- a/src/engagements/notes.rs +++ b/src/engagements/notes.rs @@ -13,6 +13,7 @@ pub struct NoteProperties { } impl NoteProperties { + #[must_use] pub fn new(body: String) -> Self { Self { body, diff --git a/src/lib.rs b/src/lib.rs index aa867a9..c8eb716 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,21 @@ +#![deny( + unreachable_pub, + missing_debug_implementations, + rustdoc::broken_intra_doc_links, + clippy::all, + clippy::perf, + clippy::pedantic, + clippy::fn_to_numeric_cast_any +)] +#![allow( + clippy::missing_errors_doc, + clippy::needless_pass_by_value, + clippy::match_same_arms, + clippy::module_name_repetitions, + clippy::missing_panics_doc, + clippy::similar_names +)] + use std::sync::Arc; use builder::HubspotBuilder; @@ -36,6 +54,7 @@ pub struct Hubspot { impl Hubspot { /// Create hubspot api + #[must_use] pub fn new(client: HubspotClient) -> Self { let portal_id = client.portal_id.clone(); let client = Arc::new(client); @@ -49,6 +68,7 @@ impl Hubspot { } /// Create Hubspot client + #[must_use] pub fn builder() -> HubspotBuilder { HubspotBuilder::new() } diff --git a/src/objects.rs b/src/objects.rs index 362d6e0..7287058 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -27,8 +27,8 @@ impl ToPath for ObjectType { /// Objects represent types of relationships or processes. /// -/// All HubSpot accounts include four standard objects: contacts, companies, deals, and tickets. -/// Depending on your HubSpot subscription, there are additional objects, such as products and custom objects. +/// All `HubSpot` accounts include four standard objects: contacts, companies, deals, and tickets. +/// Depending on your `HubSpot` subscription, there are additional objects, such as products and custom objects. /// /// Records are individual instances of an object (e.g., John Smith is a contact). For each record, you can store information in properties, track interactions, and create reports. You can also make associations between records to understand the relationships between them #[derive(Clone, Debug)] @@ -56,7 +56,7 @@ impl ObjectsManager { } } - /// Uses the object_type to return the relevant collection. + /// Uses the `object_type` to return the relevant collection. pub fn get_collection(&self, object_type: ObjectType) -> &ApiCollection { match object_type { ObjectType::Contacts => &self.contacts, diff --git a/src/owners.rs b/src/owners.rs index 073cd21..72f7aa3 100644 --- a/src/owners.rs +++ b/src/owners.rs @@ -9,12 +9,12 @@ use reqwest::Method; use crate::client::error::HubspotResult; -/// HubSpot uses owners to assign specific users to contacts, companies, deals, tickets, -/// or engagements. Any HubSpot user with access to contacts can be assigned as an owner, +/// `HubSpot` uses owners to assign specific users to contacts, companies, deals, tickets, +/// or engagements. Any `HubSpot` user with access to contacts can be assigned as an owner, /// and multiple owners can be assigned to an object by creating a custom property for -/// this purpose. Owners can only be created in HubSpot, but you can use the owners endpoints +/// this purpose. Owners can only be created in `HubSpot`, but you can use the owners endpoints /// to get their identifying details, including IDs and email addresses. This data can -/// then be assigned to CRM records in HubSpot or via property change API calls. +/// then be assigned to CRM records in `HubSpot` or via property change API calls. #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct Owner { @@ -36,7 +36,7 @@ pub struct Owner { pub updated_at: OffsetDateTime, /// Whether or not the owner has been archived pub archived: bool, - /// If teams are available for your HubSpot tier, + /// If teams are available for your `HubSpot` tier, /// this indicates which team(s) the owner can access. pub teams: Option>, } @@ -53,7 +53,7 @@ pub struct Team { /// The endpoints described here are used to get a list of the owners /// that are available for an account. To assign an owner to an object, -/// set the hubspot_owner_id property using the appropriate CRM object +/// set the `hubspot_owner_id` property using the appropriate CRM object /// update or create a request. #[derive(Clone, Debug)] pub struct OwnerApi {