Skip to content

Commit 36bec9c

Browse files
committed
fix: resolve all non-result_large_err clippy warnings
- Fix mismatched_lifetime_syntaxes: add explicit '_ to Cow<str> - Fix deref_addrof: remove unnecessary & on already-reference args - Fix useless_conversion: remove redundant .into() calls - Fix len_zero: use .is_empty() instead of .len() > 0 - Fix cmp_owned: compare BigDecimal directly with integer literal - Fix from_over_into: convert Into impl to From impl for Balance - Fix is_multiple_of: use .is_multiple_of() instead of modulo - Fix large_enum_variant: box ServerInfo and ServerState in XRPLResult - Fix unreachable_code and remove #[allow] directives in asynch/mod.rs
1 parent 969308a commit 36bec9c

4 files changed

Lines changed: 88 additions & 30 deletions

File tree

src/asynch/mod.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,33 @@ pub mod transaction;
1111
#[cfg(feature = "helpers")]
1212
pub mod wallet;
1313

14-
#[allow(unused_imports)]
15-
#[allow(clippy::needless_return)]
16-
#[allow(unused_variables)]
17-
#[allow(unreachable_code)]
18-
async fn wait_seconds(seconds: u64) {
19-
use core::time::Duration;
20-
14+
async fn wait_seconds(_seconds: u64) {
2115
#[cfg(feature = "tokio-rt")]
2216
{
23-
tokio::time::sleep(tokio::time::Duration::from_secs(seconds)).await;
24-
return;
17+
tokio::time::sleep(tokio::time::Duration::from_secs(_seconds)).await;
2518
}
2619
#[cfg(feature = "embassy-rt")]
2720
{
2821
embassy_time::Timer::after_secs(1).await;
29-
return;
3022
}
3123
#[cfg(feature = "actix-rt")]
3224
{
33-
actix_rt::time::sleep(Duration::from_secs(seconds)).await;
34-
return;
25+
use core::time::Duration;
26+
actix_rt::time::sleep(Duration::from_secs(_seconds)).await;
3527
}
3628
#[cfg(feature = "async-std-rt")]
3729
{
38-
async_std::task::sleep(Duration::from_secs(seconds)).await;
39-
return;
30+
use core::time::Duration;
31+
async_std::task::sleep(Duration::from_secs(_seconds)).await;
4032
}
4133
#[cfg(feature = "futures-rt")]
4234
{
43-
futures_timer::Delay::new(Duration::from_secs(seconds)).await;
44-
return;
35+
use core::time::Duration;
36+
futures_timer::Delay::new(Duration::from_secs(_seconds)).await;
4537
}
4638
#[cfg(feature = "smol-rt")]
4739
{
48-
smol::Timer::after(Duration::from_secs(seconds)).await;
49-
return;
40+
use core::time::Duration;
41+
smol::Timer::after(Duration::from_secs(_seconds)).await;
5042
}
5143
}

src/models/results/mod.rs

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ pub enum XRPLResult<'a> {
142142
PathFind(path_find::PathFind<'a>),
143143
Random(random::Random<'a>),
144144
RipplePathFind(ripple_path_find::RipplePathFind<'a>),
145-
ServerInfo(server_info::ServerInfo<'a>),
146-
ServerState(server_state::ServerState<'a>),
145+
ServerInfo(Box<server_info::ServerInfo<'a>>),
146+
ServerState(Box<server_state::ServerState<'a>>),
147147
Submit(submit::Submit<'a>),
148148
SubmitMultisigned(submit_multisigned::SubmitMultisigned<'a>),
149149
TransactionEntry(transaction_entry::TransactionEntry<'a>),
@@ -194,8 +194,16 @@ impl_from_result!(no_ripple_check, NoRippleCheck);
194194
impl_from_result!(path_find, PathFind);
195195
impl_from_result!(random, Random);
196196
impl_from_result!(ripple_path_find, RipplePathFind);
197-
impl_from_result!(server_info, ServerInfo);
198-
impl_from_result!(server_state, ServerState);
197+
impl<'a> From<server_info::ServerInfo<'a>> for XRPLResult<'a> {
198+
fn from(value: server_info::ServerInfo<'a>) -> Self {
199+
XRPLResult::ServerInfo(Box::new(value))
200+
}
201+
}
202+
impl<'a> From<server_state::ServerState<'a>> for XRPLResult<'a> {
203+
fn from(value: server_state::ServerState<'a>) -> Self {
204+
XRPLResult::ServerState(Box::new(value))
205+
}
206+
}
199207
impl_from_result!(submit, Submit);
200208
impl_from_result!(submit_multisigned, SubmitMultisigned);
201209
impl_from_result!(transaction_entry, TransactionEntry);
@@ -319,8 +327,34 @@ impl_try_from_result!(no_ripple_check, NoRippleCheck, NoRippleCheck);
319327
impl_try_from_result!(path_find, PathFind, PathFind);
320328
impl_try_from_result!(random, Random, Random);
321329
impl_try_from_result!(ripple_path_find, RipplePathFind, RipplePathFind);
322-
impl_try_from_result!(server_info, ServerInfo, ServerInfo);
323-
impl_try_from_result!(server_state, ServerState, ServerState);
330+
impl<'a> TryFrom<XRPLResult<'a>> for server_info::ServerInfo<'a> {
331+
type Error = XRPLModelException;
332+
333+
fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
334+
match result {
335+
XRPLResult::ServerInfo(value) => Ok(*value),
336+
res => Err(XRPLResultException::UnexpectedResultType(
337+
"ServerInfo".to_string(),
338+
res.get_name(),
339+
)
340+
.into()),
341+
}
342+
}
343+
}
344+
impl<'a> TryFrom<XRPLResult<'a>> for server_state::ServerState<'a> {
345+
type Error = XRPLModelException;
346+
347+
fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
348+
match result {
349+
XRPLResult::ServerState(value) => Ok(*value),
350+
res => Err(XRPLResultException::UnexpectedResultType(
351+
"ServerState".to_string(),
352+
res.get_name(),
353+
)
354+
.into()),
355+
}
356+
}
357+
}
324358
impl_try_from_result!(submit, Submit, Submit);
325359
impl_try_from_result!(submit_multisigned, SubmitMultisigned, SubmitMultisigned);
326360
impl_try_from_result!(transaction_entry, TransactionEntry, TransactionEntry);
@@ -545,8 +579,40 @@ impl_try_from_response!(path_find, PathFind, PathFind);
545579
impl_try_from_response!(ping, Ping, Ping);
546580
impl_try_from_response!(random, Random, Random);
547581
impl_try_from_response!(ripple_path_find, RipplePathFind, RipplePathFind);
548-
impl_try_from_response!(server_info, ServerInfo, ServerInfo);
549-
impl_try_from_response!(server_state, ServerState, ServerState);
582+
impl<'a> TryFrom<XRPLResponse<'a>> for server_info::ServerInfo<'a> {
583+
type Error = XRPLModelException;
584+
585+
fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
586+
match response.result {
587+
Some(result) => match result {
588+
XRPLResult::ServerInfo(value) => Ok(*value),
589+
res => Err(XRPLResultException::UnexpectedResultType(
590+
"ServerInfo".to_string(),
591+
res.get_name(),
592+
)
593+
.into()),
594+
},
595+
None => Err(XRPLModelException::MissingField("result".to_string())),
596+
}
597+
}
598+
}
599+
impl<'a> TryFrom<XRPLResponse<'a>> for server_state::ServerState<'a> {
600+
type Error = XRPLModelException;
601+
602+
fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
603+
match response.result {
604+
Some(result) => match result {
605+
XRPLResult::ServerState(value) => Ok(*value),
606+
res => Err(XRPLResultException::UnexpectedResultType(
607+
"ServerState".to_string(),
608+
res.get_name(),
609+
)
610+
.into()),
611+
},
612+
None => Err(XRPLModelException::MissingField("result".to_string())),
613+
}
614+
}
615+
}
550616
impl_try_from_response!(submit, Submit, Submit);
551617
impl_try_from_response!(submit_multisigned, SubmitMultisigned, SubmitMultisigned);
552618
impl_try_from_response!(transaction_entry, TransactionEntry, TransactionEntry);

src/models/transactions/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ where
269269
{
270270
pub fn is_signed(&self) -> bool {
271271
if let Some(signers) = &self.signers {
272-
signers.iter().all(|signer| {
273-
!signer.txn_signature.is_empty() && !signer.signing_pub_key.is_empty()
274-
})
272+
signers
273+
.iter()
274+
.all(|signer| !signer.txn_signature.is_empty() && !signer.signing_pub_key.is_empty())
275275
} else {
276276
self.txn_signature.is_some() && self.signing_pub_key.is_some()
277277
}

src/utils/txn_parser/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a: 'b, 'b> From<Amount<'a>> for Balance<'b> {
3737
}
3838

3939
impl<'a> From<Balance<'a>> for Amount<'a> {
40-
fn from(balance: Balance<'a>) -> Amount<'a> {
40+
fn from(balance: Balance<'a>) -> Self {
4141
if balance.currency == "XRP" {
4242
Amount::XRPAmount(balance.value.into())
4343
} else {

0 commit comments

Comments
 (0)