diff --git a/generator/src/lib.rs b/generator/src/lib.rs index bff68f1b2..dab28979e 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -673,7 +673,7 @@ fn to_type_tokens(type_name: &str, reference: Option<&vkxml::ReferenceType>) -> fn map_identifier_to_rust(term: Term) -> Term { match term.as_str() { "VK_MAKE_VERSION" => Term::intern("crate::vk::make_version"), - s => Term::intern(&constant_name(&s)), + s => Term::intern(constant_name(s)), } } @@ -762,8 +762,7 @@ impl FieldExt for vkxml::Field { .expect("Should have size"); // Make sure we also rename the constant, that is // used inside the static array - let size = constant_name(size); - let size = Term::intern(&size); + let size = Term::intern(constant_name(size)); // arrays in c are always passed as a pointer if is_ffi_param { quote!(&[#ty; #size]) @@ -1205,7 +1204,7 @@ pub fn generate_extension<'a>( } pub fn generate_define(define: &vkxml::Define) -> Tokens { let name = constant_name(&define.name); - let ident = Ident::from(name.as_str()); + let ident = Ident::from(name); let deprecated = define .comment .as_ref() @@ -2208,8 +2207,9 @@ pub fn generate_feature<'a>( #device } } -pub fn constant_name(name: &str) -> String { - name.replace("VK_", "") + +pub fn constant_name(name: &str) -> &str { + name.strip_prefix("VK_").unwrap_or(name) } pub fn generate_constant<'a>( @@ -2219,7 +2219,7 @@ pub fn generate_constant<'a>( cache.insert(constant.name.as_str()); let c = Constant::from_constant(constant); let name = constant_name(&constant.name); - let ident = Ident::from(name.as_str()); + let ident = Ident::from(name); let ty = if name == "TRUE" || name == "FALSE" { CType::Bool32 } else {