chore: address some clippy lints arising from v2 code (#6015)

This commit is contained in:
Sanchith Hegde
2024-09-25 16:21:27 +05:30
committed by GitHub
parent 4dac86cebf
commit dec0a57f76
16 changed files with 115 additions and 112 deletions

View File

@ -63,13 +63,24 @@ impl From<AlphaNumericIdError> for CellIdError {
impl CellId {
/// Create a new cell id from a string
pub fn from_str(cell_id_string: impl AsRef<str>) -> Result<Self, CellIdError> {
fn from_str(cell_id_string: impl AsRef<str>) -> Result<Self, CellIdError> {
let trimmed_input_string = cell_id_string.as_ref().trim().to_string();
let alphanumeric_id = AlphaNumericId::from(trimmed_input_string.into())?;
let length_id = LengthId::from_alphanumeric_id(alphanumeric_id)?;
Ok(Self(length_id))
}
/// Create a new cell id from a string
pub fn from_string(
input_string: impl AsRef<str>,
) -> error_stack::Result<Self, errors::ValidationError> {
Self::from_str(input_string).change_context(
errors::ValidationError::IncorrectValueProvided {
field_name: "cell_id",
},
)
}
/// Get the string representation of the cell id
fn get_string_repr(&self) -> &str {
&self.0 .0 .0
@ -115,7 +126,7 @@ impl GlobalId {
pub(crate) fn from_string(
input_string: std::borrow::Cow<'static, str>,
) -> Result<Self, GlobalIdError> {
let length_id = LengthId::from(input_string.into())?;
let length_id = LengthId::from(input_string)?;
let input_string = &length_id.0 .0;
let (cell_id, remaining) = input_string
.split_once("_")

View File

@ -1,4 +1,3 @@
use diesel::{backend::Backend, deserialize::FromSql, serialize::ToSql, sql_types};
use error_stack::ResultExt;
use crate::{
@ -7,6 +6,7 @@ use crate::{
id_type::global_id::{CellId, GlobalEntity, GlobalId, GlobalIdError},
};
/// A global id that can be used to identify a payment method
#[derive(
Debug,
Clone,
@ -27,7 +27,7 @@ pub enum GlobalPaymentMethodIdError {
}
impl GlobalPaymentMethodId {
/// Create a new GlobalPaymentMethodId from celll id information
/// Create a new GlobalPaymentMethodId from cell id information
pub fn generate(cell_id: &str) -> error_stack::Result<Self, GlobalPaymentMethodIdError> {
let cell_id = CellId::from_str(cell_id)
.change_context(GlobalPaymentMethodIdError::ConstructionError)
@ -36,10 +36,12 @@ impl GlobalPaymentMethodId {
Ok(Self(global_id))
}
/// Get string representation of the id
pub fn get_string_repr(&self) -> &str {
self.0.get_string_repr()
}
/// Construct a new GlobalPaymentMethodId from a string
pub fn generate_from_string(value: String) -> CustomResult<Self, GlobalPaymentMethodIdError> {
let id = GlobalId::from_string(value.into())
.change_context(GlobalPaymentMethodIdError::ConstructionError)?;
@ -47,7 +49,7 @@ impl GlobalPaymentMethodId {
}
}
impl<DB> diesel::Queryable<sql_types::Text, DB> for GlobalPaymentMethodId
impl<DB> diesel::Queryable<diesel::sql_types::Text, DB> for GlobalPaymentMethodId
where
DB: diesel::backend::Backend,
Self: diesel::deserialize::FromSql<diesel::sql_types::Text, DB>,
@ -58,10 +60,10 @@ where
}
}
impl<DB> ToSql<sql_types::Text, DB> for GlobalPaymentMethodId
impl<DB> diesel::serialize::ToSql<diesel::sql_types::Text, DB> for GlobalPaymentMethodId
where
DB: Backend,
GlobalId: ToSql<sql_types::Text, DB>,
DB: diesel::backend::Backend,
GlobalId: diesel::serialize::ToSql<diesel::sql_types::Text, DB>,
{
fn to_sql<'b>(
&'b self,
@ -71,10 +73,10 @@ where
}
}
impl<DB> FromSql<sql_types::Text, DB> for GlobalPaymentMethodId
impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Text, DB> for GlobalPaymentMethodId
where
DB: Backend,
GlobalId: FromSql<sql_types::Text, DB>,
DB: diesel::backend::Backend,
GlobalId: diesel::deserialize::FromSql<diesel::sql_types::Text, DB>,
{
fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
let global_id = GlobalId::from_sql(value)?;