Set a flag bit by name. Returns true if the flag was found and set, false for an unknown flag name. # Errors Returns an error message if the `name` is known but couldn't be applied due to it being a semantic error.
(&mut self, name: &str)
| 206 | /// Returns an error message if the `name` is known but couldn't be applied |
| 207 | /// due to it being a semantic error. |
| 208 | pub fn set_by_name(&mut self, name: &str) -> Result<bool, &'static str> { |
| 209 | *self = match name { |
| 210 | "notrap" => self.with_trap_code(None), |
| 211 | "aligned" => self.with_aligned(), |
| 212 | "readonly" => self.with_readonly(), |
| 213 | "little" => { |
| 214 | if self.flags.explicit_endianness() == Some(Endianness::Big) { |
| 215 | return Err("cannot set both big and little endian bits"); |
| 216 | } |
| 217 | self.with_endianness(Endianness::Little) |
| 218 | } |
| 219 | "big" => { |
| 220 | if self.flags.explicit_endianness() == Some(Endianness::Little) { |
| 221 | return Err("cannot set both big and little endian bits"); |
| 222 | } |
| 223 | self.with_endianness(Endianness::Big) |
| 224 | } |
| 225 | "can_move" => self.with_can_move(), |
| 226 | |
| 227 | other => match TrapCode::from_str(other) { |
| 228 | Ok(code) => self.with_trap_code(Some(code)), |
| 229 | Err(()) => return Ok(false), |
| 230 | }, |
| 231 | }; |
| 232 | Ok(true) |
| 233 | } |
| 234 | |
| 235 | /// Return endianness of the memory access. This will return the endianness |
| 236 | /// explicitly specified by the flags if any, and will default to the native |
no test coverage detected