Skip to content

Commit f7410c0

Browse files
author
bitfl0wer
committed
Manually impl From<Self::Uint> for Self and vice versa
1 parent 91fb343 commit f7410c0

5 files changed

Lines changed: 70 additions & 0 deletions

File tree

sqlx-pg-uint/src/u128.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ pub struct PgU128 {
1515
inner: BigDecimal,
1616
}
1717

18+
impl From<PgU128> for u128 {
19+
fn from(value: PgU128) -> Self {
20+
value.inner.to_string().parse().unwrap()
21+
}
22+
}
23+
24+
impl From<u128> for PgU128 {
25+
fn from(value: u128) -> Self {
26+
Self {
27+
inner: BigDecimal::from(value),
28+
}
29+
}
30+
}
31+
1832
#[cfg(test)]
1933
mod pg_u128_tests {
2034
use bigdecimal::num_bigint::BigInt;

sqlx-pg-uint/src/u16.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ pub struct PgU16 {
1515
inner: BigDecimal,
1616
}
1717

18+
impl From<PgU16> for u16 {
19+
fn from(value: PgU16) -> Self {
20+
value.inner.to_string().parse().unwrap()
21+
}
22+
}
23+
24+
impl From<u16> for PgU16 {
25+
fn from(value: u16) -> Self {
26+
Self {
27+
inner: BigDecimal::from(value),
28+
}
29+
}
30+
}
31+
1832
#[cfg(test)]
1933
mod pg_u16_tests {
2034
use bigdecimal::num_bigint::BigInt;

sqlx-pg-uint/src/u32.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ pub struct PgU32 {
1414
inner: BigDecimal,
1515
}
1616

17+
impl From<PgU32> for u32 {
18+
fn from(value: PgU32) -> Self {
19+
value.inner.to_string().parse().unwrap()
20+
}
21+
}
22+
23+
impl From<u32> for PgU32 {
24+
fn from(value: u32) -> Self {
25+
Self {
26+
inner: BigDecimal::from(value),
27+
}
28+
}
29+
}
30+
1731
#[cfg(test)]
1832
mod pg_u32_tests {
1933
use bigdecimal::num_bigint::BigInt;

sqlx-pg-uint/src/u64.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ pub struct PgU64 {
1414
inner: BigDecimal,
1515
}
1616

17+
impl From<PgU64> for u64 {
18+
fn from(value: PgU64) -> Self {
19+
value.inner.to_string().parse().unwrap()
20+
}
21+
}
22+
23+
impl From<u64> for PgU64 {
24+
fn from(value: u64) -> Self {
25+
Self {
26+
inner: BigDecimal::from(value),
27+
}
28+
}
29+
}
30+
1731
#[cfg(test)]
1832
mod pg_u64_tests {
1933
use bigdecimal::num_bigint::BigInt;

sqlx-pg-uint/src/u8.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ pub struct PgU8 {
1515
inner: BigDecimal,
1616
}
1717

18+
impl From<PgU8> for u8 {
19+
fn from(value: PgU8) -> Self {
20+
value.inner.to_string().parse().unwrap()
21+
}
22+
}
23+
24+
impl From<u8> for PgU8 {
25+
fn from(value: u8) -> Self {
26+
Self {
27+
inner: BigDecimal::from(value),
28+
}
29+
}
30+
}
31+
1832
#[cfg(test)]
1933
mod pg_u8_tests {
2034
use bigdecimal::num_bigint::BigInt;

0 commit comments

Comments
 (0)