mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-15 06:20:50 +00:00
Add auxiliary as_* to Value
This commit is contained in:
parent
22aea1100f
commit
174dcdca5a
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "sqlite"
|
||||
version = "0.19.2"
|
||||
version = "0.19.3"
|
||||
authors = ["Ivan Ukhov <ivan.ukhov@gmail.com>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/stainless-steel/sqlite"
|
||||
|
40
src/lib.rs
40
src/lib.rs
@ -174,7 +174,7 @@ pub enum Value {
|
||||
Binary(Vec<u8>),
|
||||
/// A floating-point number.
|
||||
Float(f64),
|
||||
/// An integer.
|
||||
/// An integer number.
|
||||
Integer(i64),
|
||||
/// A string.
|
||||
String(String),
|
||||
@ -202,6 +202,44 @@ impl error::Error for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl Value {
|
||||
/// Return the binary data if the value is `Binary`.
|
||||
#[inline]
|
||||
pub fn as_binary(&self) -> Option<&[u8]> {
|
||||
if let &Value::Binary(ref value) = self {
|
||||
return Some(value);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Return the floating-point number if the value is `Float`.
|
||||
#[inline]
|
||||
pub fn as_float(&self) -> Option<f64> {
|
||||
if let &Value::Float(value) = self {
|
||||
return Some(value);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Return the integer number if the value is `Integer`.
|
||||
#[inline]
|
||||
pub fn as_integer(&self) -> Option<i64> {
|
||||
if let &Value::Integer(value) = self {
|
||||
return Some(value);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Return the string if the value is `String`.
|
||||
#[inline]
|
||||
pub fn as_string(&self) -> Option<&str> {
|
||||
if let &Value::String(ref value) = self {
|
||||
return Some(value);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
mod connection;
|
||||
mod cursor;
|
||||
mod statement;
|
||||
|
Loading…
x
Reference in New Issue
Block a user