Skip to content

Commit

Permalink
generator: Return str reference from constant_name
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Nov 24, 2020
1 parent fdc5910 commit 68f7d49
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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>(
Expand All @@ -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 {
Expand Down

0 comments on commit 68f7d49

Please sign in to comment.