diff options
author | Paul Masurel <paul.masurel@gmail.com> | 2017-05-01 15:45:31 +0800 |
---|---|---|
committer | Paul Masurel <paul.masurel@gmail.com> | 2017-05-04 16:46:13 +0800 |
commit | afdfb1a69b23f4a492ecacec828658c7a3b27d87 (patch) | |
tree | d694a881ce22b12caa7de496f57bc0a02f1c4492 /src/schema/value.rs | |
parent | b26ad1d57a3f7b0f93002d0811d28df02836e74e (diff) |
Compiling... fastfield not implemented yet
Diffstat (limited to 'src/schema/value.rs')
-rw-r--r-- | src/schema/value.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/schema/value.rs b/src/schema/value.rs index 16b6e45..af14683 100644 --- a/src/schema/value.rs +++ b/src/schema/value.rs @@ -10,8 +10,10 @@ use std::io::Read; pub enum Value { /// The str type is used for any text information. Str(String), - /// Unsigned 32-bits Integer `u64` + /// Unsigned 64-bits Integer `u64` U64(u64), + /// Signed 64-bits Integer `i64` + I64(i64) } impl Value { @@ -44,6 +46,21 @@ impl Value { } } } + + /// Returns the i64-value, provided the value is of the `I64` type. + /// + /// # Panics + /// If the value is not of type `I64` + pub fn i64_value(&self) -> i64 { + match *self { + Value::I64(ref value) => { + *value + } + _ => { + panic!("This is not a text field.") + } + } + } } impl From<String> for Value { @@ -67,6 +84,7 @@ impl<'a> From<&'a str> for Value { const TEXT_CODE: u8 = 0; const U64_CODE: u8 = 1; +const I64_CODE: u8 = 2; impl BinarySerializable for Value { @@ -80,6 +98,10 @@ impl BinarySerializable for Value { Value::U64(ref val) => { written_size += try!(U64_CODE.serialize(writer)); written_size += try!(val.serialize(writer)); + }, + Value::I64(ref val) => { + written_size += try!(I64_CODE.serialize(writer)); + written_size += try!(val.serialize(writer)); }, } Ok(written_size) @@ -95,6 +117,10 @@ impl BinarySerializable for Value { let value = try!(u64::deserialize(reader)); Ok(Value::U64(value)) } + I64_CODE => { + let value = try!(i64::deserialize(reader)); + Ok(Value::I64(value)) + } _ => { Err(io::Error::new(io::ErrorKind::InvalidData, format!("No field type is associated with code {:?}", type_code))) } |