Add method to get type
Getty Ritter
7 years ago
| 44 | 44 | self.fields.len() |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | pub fn get_type<'a>(&'a self) -> Result<&'a str, RecError> { | |
| 48 | match self.rec_type { | |
| 49 | Some(ref t) => Ok(t), | |
| 50 | None => Err(RecError::NoType), | |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 47 | 54 | /// Return the value of the field named by the argument if it |
| 48 | 55 | /// exists |
| 49 | 56 | pub fn get<'a>(&'a self, name: &str) -> Result<&'a str, RecError> { |
| 144 | 151 | MissingField { |
| 145 | 152 | name: String, |
| 146 | 153 | }, |
| 154 | ||
| 155 | #[fail(display = "Missing type for record")] | |
| 156 | NoType, | |
| 147 | 157 | } |
| 148 | 158 | |
| 149 | 159 | |