Return &'static str from HeaderDef.get_headername()

This commit is contained in:
Alexander Krotov
2020-02-09 19:44:49 +03:00
committed by holger krekel
parent df252c4704
commit b4573e341f
2 changed files with 8 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
#[derive(Debug, Display, Clone, PartialEq, Eq, EnumVariantNames)]
use crate::strum::AsStaticRef;
#[derive(Debug, Display, Clone, PartialEq, Eq, EnumVariantNames, AsStaticStr)]
#[strum(serialize_all = "kebab_case")]
#[allow(dead_code)]
pub enum HeaderDef {
@@ -43,8 +45,8 @@ pub enum HeaderDef {
impl HeaderDef {
/// Returns the corresponding Event id.
pub fn get_headername(&self) -> String {
self.to_string()
pub fn get_headername(&self) -> &'static str {
self.as_static()
}
}
@@ -55,8 +57,8 @@ mod tests {
#[test]
/// Test that kebab_case serialization works as expected
fn kebab_test() {
assert_eq!(HeaderDef::From_.to_string(), "from");
assert_eq!(HeaderDef::From_.get_headername(), "from");
assert_eq!(HeaderDef::_TestHeader.to_string(), "test-header");
assert_eq!(HeaderDef::_TestHeader.get_headername(), "test-header");
}
}