pub struct Value { /* private fields */ }Expand description
A dynamic value.
Implementations§
Source§impl Value
impl Value
Sourcepub const fn null() -> Self
pub const fn null() -> Self
Construct a null value.
§Examples
use sqlite_ll::Value;
let value = Value::null();
assert!(value.is_null());Sourcepub const fn blob(value: Vec<u8>) -> Self
pub const fn blob(value: Vec<u8>) -> Self
Construct a blob value.
§Examples
use sqlite_ll::Value;
let value = Value::blob(Vec::new());
assert_eq!(value.as_blob(), Some(&[][..]));Sourcepub const fn text(value: String) -> Self
pub const fn text(value: String) -> Self
Construct a text value.
§Examples
use sqlite_ll::Value;
let value = Value::text(String::new());
assert_eq!(value.as_text(), Some(""));
let value = Value::text(String::from("hello"));
assert_eq!(value.as_text(), Some("hello"));Sourcepub const fn float(value: f64) -> Self
pub const fn float(value: f64) -> Self
Construct a float value.
§Examples
use sqlite_ll::Value;
let value = Value::float(42.0);
assert_eq!(value.as_float(), Some(42.0));Sourcepub const fn integer(value: i64) -> Self
pub const fn integer(value: i64) -> Self
Construct a integer value.
§Examples
use sqlite_ll::Value;
let value = Value::integer(42);
assert_eq!(value.as_integer(), Some(42));Sourcepub const fn is_null(&self) -> bool
pub const fn is_null(&self) -> bool
Return whether the value is Null.
§Examples
use sqlite_ll::Value;
let value = Value::null();
assert!(value.is_null());Sourcepub const fn as_blob(&self) -> Option<&[u8]>
pub const fn as_blob(&self) -> Option<&[u8]>
Return the binary data if the value is Binary.
§Examples
use sqlite_ll::Value;
let value = Value::blob(Vec::new());
assert_eq!(value.as_blob(), Some(&[][..]));Sourcepub const fn as_text(&self) -> Option<&str>
pub const fn as_text(&self) -> Option<&str>
Return the string if the value is String.
§Examples
use sqlite_ll::Value;
let value = Value::text(String::new());
assert_eq!(value.as_text(), Some(""));
let value = Value::text(String::from("hello"));
assert_eq!(value.as_text(), Some("hello"));Sourcepub const fn as_float(&self) -> Option<f64>
pub const fn as_float(&self) -> Option<f64>
Return the floating-point number if the value is Float.
§Examples
use sqlite_ll::Value;
let value = Value::float(42.0);
assert_eq!(value.as_float(), Some(42.0));Sourcepub const fn as_integer(&self) -> Option<i64>
pub const fn as_integer(&self) -> Option<i64>
Return the integer number if the value is Integer.
§Examples
use sqlite_ll::Value;
let value = Value::integer(42);
assert_eq!(value.as_integer(), Some(42));Trait Implementations§
impl Bindable for Value
§Examples
use sqlite_ll::{Connection, Value};
let c = Connection::open_memory()?;
c.execute(r##"
CREATE TABLE users (name TEXT, age INTEGER);
INSERT INTO users (name, age) VALUES ('Alice', NULL), ('Bob', 30);
"##)?;
let mut stmt = c.prepare("SELECT name FROM users WHERE age IS ?")?;
stmt.bind(1, Value::null())?;
let mut names = Vec::new();
while let Some(row) = stmt.next()? {
names.push(row.read::<String>(0)?);
}
assert_eq!(names, vec![String::from("Alice")]);impl Readable for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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