pub struct PgFloat8(/* private fields */);Expand description
A PostgreSQL double precision, equal, ordered and hashed as float8_cmp_internal compares
it, with NaN equal to itself and above Infinity, and -0 equal to 0.
Its Display is float8out, the shortest text that reads back to the same
double, in fixed notation for decimal exponents from -4 to 14 and in exponential notation
otherwise.
use sql_values::postgres::PgFloat8;
let float8 = |text| PgFloat8::parse(text).unwrap();
assert_eq!(float8(" 0.1 ").to_string(), "0.1");
assert_eq!(float8("1e15").to_string(), "1e+15");
assert_eq!(float8("0.00001").to_string(), "1e-05");
assert_eq!(float8("-inf").to_string(), "-Infinity");
assert_eq!(float8("0x1.8p1").value(), 3.0);
assert_eq!(float8("-0"), float8("0"));
assert!(float8("NaN") > float8("Infinity"));
assert_eq!(PgFloat8::from(2.5).to_string(), "2.5");
let distinct: std::collections::HashSet<_> =
["0", "-0", "1", "1.0", "NaN", "-nan"].map(|text| float8(text)).into_iter().collect();
assert_eq!(distinct.len(), 3);Implementations§
Source§impl PgFloat8
impl PgFloat8
Sourcepub fn parse(text: &str) -> Result<Self, Float8Error>
pub fn parse(text: &str) -> Result<Self, Float8Error>
Read text as float8in reads it, C’s strtod between blanks, refusing a nonzero number
that rounds to zero and one beyond the finite doubles.
§Errors
The Float8Error whose message PostgreSQL raises for text.
Trait Implementations§
impl Copy for PgFloat8
impl Eq for PgFloat8
Source§impl Ord for PgFloat8
impl Ord for PgFloat8
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Auto Trait Implementations§
impl Forget for PgFloat8
impl Freeze for PgFloat8
impl Move for PgFloat8
impl RefUnwindSafe for PgFloat8
impl Send for PgFloat8
impl Sync for PgFloat8
impl Unpin for PgFloat8
impl UnsafeUnpin for PgFloat8
impl UnwindSafe for PgFloat8
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more