Attribute::to_str() - New function, hopefully only used for printing errors

parent d5e0162f
......@@ -17,6 +17,22 @@ impl FromStr for Attribute {
}
}
impl Attribute {
// This is horribly inefficient, but for now I'm too lazy to have a
// compile-time bijective mapping from attributes to names. Hopefully
// this function is only called when *printing* errors, which, uh,
// should not be done too often.
pub fn to_str(&self) -> &'static str {
for (k, v) in ATTRIBUTES.entries() {
if *v == *self {
return k;
}
}
unreachable!();
}
}
#[no_mangle]
pub extern "C" fn rsvg_attribute_from_name(
raw_name: *const libc::c_char,
......@@ -71,4 +87,11 @@ mod tests {
));
assert!(!res);
}
#[test]
fn converts_attributes_back_to_strings() {
assert_eq!(Attribute::ClipPath.to_str(), "clip-path");
assert_eq!(Attribute::KernelUnitLength.to_str(), "kernelUnitLength");
assert_eq!(Attribute::Offset.to_str(), "offset");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment