Skip to content

Commit

Permalink
Use macro to imopl From for Decimal for number types (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX authored Mar 7, 2024
1 parent 37ce258 commit 84bfa9b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
31 changes: 12 additions & 19 deletions src/core/types/decimal192.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,19 @@ impl FromStr for Decimal192 {
}
}

impl From<u32> for Decimal {
fn from(value: u32) -> Self {
ScryptoDecimal192::from(value).into()
}
}
impl From<u64> for Decimal {
fn from(value: u64) -> Self {
ScryptoDecimal192::from(value).into()
}
}
impl From<i32> for Decimal {
fn from(value: i32) -> Self {
ScryptoDecimal192::from(value).into()
}
}
impl From<i64> for Decimal {
fn from(value: i64) -> Self {
ScryptoDecimal192::from(value).into()
}
macro_rules! forward_from_for_num {
($num_type: ty) => {
impl From<$num_type> for Decimal {
fn from(value: $num_type) -> Self {
ScryptoDecimal192::from(value).into()
}
}
};
}
forward_from_for_num!(u32);
forward_from_for_num!(u64);
forward_from_for_num!(i32);
forward_from_for_num!(i64);

impl From<f32> for Decimal {
fn from(value: f32) -> Self {
Expand Down
2 changes: 0 additions & 2 deletions src/core/types/epoch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pub use crate::prelude::*;
use radix_engine::types::Epoch as ScryptoEpoch;

// use radix_engine_common::types::Epoch as ScryptoEpoch;

// Generate the FfiConverter needed by UniFFI for newtype `Epoch`.
uniffi::custom_newtype!(Epoch, u64);

Expand Down
2 changes: 1 addition & 1 deletion src/profile/v100/address/account_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl AccountAddress {
#[cfg(test)]
mod tests {

use crate::prelude::*;
use super::*;

#[allow(clippy::upper_case_acronyms)]
type SUT = AccountAddress;
Expand Down
10 changes: 10 additions & 0 deletions src/profile/v100/address/wrap_ret_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ decl_ret_wrapped_address!(
/// * GlobalVirtualSecp256k1Identity,
/// * GlobalVirtualEd25519Identity
///
/// ```
/// extern crate sargon;
/// use sargon::prelude::*;
///
/// assert_eq!(
/// "identity_rdx12tgzjrz9u0xz4l28vf04hz87eguclmfaq4d2p8f8lv7zg9ssnzku8j".parse::<IdentityAddress>().unwrap().network_id(),
/// NetworkID::Mainnet
/// );
/// ```
///
/// Implementation wise we wrap [Radix Engine Toolkit's `CanonicalIdentityAddress`][ret], and
/// give it UniFFI support, as a `uniffi::Record` (we also own Serde).
///
Expand Down
8 changes: 8 additions & 0 deletions src/profile/v100/profile.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
use crate::prelude::*;

/// Representation of the Radix Wallet, contains a list of
/// users Accounts, Personas, Authorized Dapps per network
/// the user has used. It also contains all FactorSources,
/// FactorInstances and wallet App preferences.
///
/// ```
/// extern crate sargon;
/// use sargon::prelude::*;
///
/// assert_eq!(Profile::sample(), Profile::sample())
/// ```
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, uniffi::Record,
)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use transaction::model::TransactionHeaderV1 as ScryptoTransactionHeader;

use crate::prelude::*;

use transaction::model::TransactionHeaderV1 as ScryptoTransactionHeader;

#[derive(
Debug, Clone, PartialEq, Eq, Hash, derive_more::Display, uniffi::Record,
)]
Expand Down

0 comments on commit 84bfa9b

Please sign in to comment.