Repository navigation
Expand file tree
/
Copy pathfloat.rs
More file actions
58 lines (50 loc) · 1.34 KB
/
Copy pathfloat.rs
File metadata and controls
58 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::decode::{Decode, DecodeError};
use crate::encode::Encode;
use crate::postgres::protocol::TypeId;
use crate::postgres::types::PgTypeInfo;
use crate::postgres::Postgres;
use crate::types::Type;
impl Type<Postgres> for f32 {
fn type_info() -> PgTypeInfo {
PgTypeInfo::new(TypeId::FLOAT4)
}
}
impl Type<Postgres> for [f32] {
fn type_info() -> PgTypeInfo {
PgTypeInfo::new(TypeId::ARRAY_FLOAT4)
}
}
impl Encode<Postgres> for f32 {
fn encode(&self, buf: &mut Vec<u8>) {
<i32 as Encode<Postgres>>::encode(&(self.to_bits() as i32), buf)
}
}
impl Decode<Postgres> for f32 {
fn decode(buf: &[u8]) -> Result<Self, DecodeError> {
Ok(f32::from_bits(
<i32 as Decode<Postgres>>::decode(buf)? as u32
))
}
}
impl Type<Postgres> for f64 {
fn type_info() -> PgTypeInfo {
PgTypeInfo::new(TypeId::FLOAT8)
}
}
impl Type<Postgres> for [f64] {
fn type_info() -> PgTypeInfo {
PgTypeInfo::new(TypeId::ARRAY_FLOAT8)
}
}
impl Encode<Postgres> for f64 {
fn encode(&self, buf: &mut Vec<u8>) {
<i64 as Encode<Postgres>>::encode(&(self.to_bits() as i64), buf)
}
}
impl Decode<Postgres> for f64 {
fn decode(buf: &[u8]) -> Result<Self, DecodeError> {
Ok(f64::from_bits(
<i64 as Decode<Postgres>>::decode(buf)? as u64
))
}
}