From 174dcdca5a8eaab391cc966b076ec5f91924a639 Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Mon, 3 Aug 2015 22:00:53 -0400 Subject: [PATCH] Add auxiliary as_* to Value --- Cargo.toml | 2 +- src/lib.rs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 477641b..09c0485 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlite" -version = "0.19.2" +version = "0.19.3" authors = ["Ivan Ukhov "] license = "MIT" repository = "https://github.com/stainless-steel/sqlite" diff --git a/src/lib.rs b/src/lib.rs index 5076490..04c9878 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,7 +174,7 @@ pub enum Value { Binary(Vec), /// 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 { + 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 { + 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;