Skip to content

Commit

Permalink
Fix clippy 1.83 warning
Browse files Browse the repository at this point in the history
  • Loading branch information
fengalin committed Dec 7, 2024
1 parent ec84749 commit 15cb980
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
24 changes: 8 additions & 16 deletions src/nameutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@ use std::{borrow::Cow, collections::HashMap, path::*, sync::OnceLock};

use crate::case::*;

static mut CRATE_NAME_OVERRIDES: Option<HashMap<String, String>> = None;
static CRATE_NAME_OVERRIDES: OnceLock<HashMap<String, String>> = OnceLock::new();

pub(crate) fn set_crate_name_overrides(overrides: HashMap<String, String>) {
unsafe {
assert!(
CRATE_NAME_OVERRIDES.is_none(),
"Crate name overrides already set"
);
CRATE_NAME_OVERRIDES = Some(overrides);
}
assert!(
CRATE_NAME_OVERRIDES.set(overrides).is_ok(),
"Crate name overrides already set"
);
}

fn get_crate_name_override(crate_name: &str) -> Option<String> {
unsafe {
if let Some(ref overrides) = CRATE_NAME_OVERRIDES {
if let Some(crate_name) = overrides.get(crate_name) {
return Some(crate_name.clone());
}
}
None
}
CRATE_NAME_OVERRIDES
.get()
.and_then(|overrides| overrides.get(crate_name).cloned())
}

pub fn split_namespace_name(name: &str) -> (Option<&str>, &str) {
Expand Down
6 changes: 3 additions & 3 deletions src/writer/to_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ impl ToCode for Chunk {
let mut v: Vec<String> = Vec::with_capacity(6);
if is_detailed {
v.push(format!(
r#"let detailed_signal_name = detail.map(|name| {{ format!("{signal}::{{name}}\0") }});"#
r#"let detailed_signal_name = detail.map(|name| {{ format!(c"{signal}::{{name}}") }});"#
));
v.push(format!(
r#"let signal_name: &[u8] = detailed_signal_name.as_ref().map_or(&b"{signal}\0"[..], |n| n.as_bytes());"#
r#"let signal_name: &[u8] = detailed_signal_name.as_ref().map_or(&c"{signal}"[..], |n| n.as_bytes());"#
));
v.push(
"connect_raw(self.as_ptr() as *mut _, signal_name.as_ptr() as *const _,"
.to_string(),
);
} else {
v.push(format!(
"connect_raw(self.as_ptr() as *mut _, b\"{signal}\\0\".as_ptr() as *const _,"
"connect_raw(self.as_ptr() as *mut _, c\"{signal}\".as_ptr() as *const _,"
));
}
let self_str = if in_trait { "Self, " } else { "" };
Expand Down

0 comments on commit 15cb980

Please sign in to comment.