pub enum Value {
Null,
Bool(bool),
Integer(i64),
Float(f64),
String(String),
Bytes(Vec<u8>),
}
Expand description
Represents a value from a PostgreSQL query result.
This enum provides type-safe access to various PostgreSQL data types and includes conversion methods for common Rust types.
Variants§
Implementations§
Source§impl Value
impl Value
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Try to get the value as a string reference.
Returns None
if the value is not a String.
§Example
use pgwire_lite::Value;
let val = Value::from("hello");
assert_eq!(val.as_str(), Some("hello"));
let val = Value::Integer(42);
assert_eq!(val.as_str(), None);
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Try to get the value as a boolean.
Returns Some(bool)
if the value is a boolean or a string that can be
interpreted as a boolean (e.g., “true”, “yes”, “1”).
Returns None
for other types or strings that cannot be parsed as booleans.
§Example
use pgwire_lite::Value;
let val = Value::Bool(true);
assert_eq!(val.as_bool(), Some(true));
let val = Value::from("yes");
assert_eq!(val.as_bool(), Some(true));
let val = Value::from("0");
assert_eq!(val.as_bool(), Some(false));
let val = Value::from("invalid");
assert_eq!(val.as_bool(), None);
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Try to get the value as a 64-bit signed integer.
Returns Some(i64)
if the value is an integer, a float that can be
converted to an integer, or a string that can be parsed as an integer.
Returns None
for other types or values that cannot be converted.
§Example
use pgwire_lite::Value;
let val = Value::Integer(42);
assert_eq!(val.as_i64(), Some(42));
let val = Value::Float(42.0);
assert_eq!(val.as_i64(), Some(42));
let val = Value::from("42");
assert_eq!(val.as_i64(), Some(42));
let val = Value::from("invalid");
assert_eq!(val.as_i64(), None);
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Try to get the value as a 64-bit floating point number.
Returns Some(f64)
if the value is a float, an integer, or a string
that can be parsed as a float.
Returns None
for other types or values that cannot be converted.
§Example
use pgwire_lite::Value;
let val = Value::Float(3.14);
assert_eq!(val.as_f64(), Some(3.14));
let val = Value::Integer(42);
assert_eq!(val.as_f64(), Some(42.0));
let val = Value::from("3.14");
assert_eq!(val.as_f64(), Some(3.14));
let val = Value::from("invalid");
assert_eq!(val.as_f64(), None);