Add auxiliary as_* to Value

This commit is contained in:
Ivan Ukhov 2015-08-03 22:00:53 -04:00
parent 22aea1100f
commit 174dcdca5a
2 changed files with 40 additions and 2 deletions

View File

@ -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"

View File

@ -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;