Skip to content

Commit 232c814

Browse files
committed
Use the linkme shorthand for function elements
It is a new feature available in linkme 0.2.1. So the linkme version requirement is bumped up to 0.2.1.
1 parent 5ef9a97 commit 232c814

File tree

2 files changed

+1
-16
lines changed

2 files changed

+1
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["trait", "cast", "any"]
1212

1313
[dependencies]
1414
once_cell = "1.3.1"
15-
linkme = "0.1.6"
15+
linkme = "0.2.1"
1616
intertrait-macros = { version = "=0.1.0", path = "macros" }
1717

1818
[dev-dependencies]

macros/src/gen_caster.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ use quote::quote;
1010
use quote::ToTokens;
1111

1212
pub fn generate_caster(ty: &impl ToTokens, trait_: &Path) -> TokenStream {
13-
let mut static_buf = [0u8; STATIC_BUF_LEN];
14-
let static_var = format_ident!("{}", generate_static(&mut static_buf));
1513
let mut fn_buf = [0u8; FN_BUF_LEN];
1614
let fn_ident = format_ident!("{}", generate_fn(&mut fn_buf));
1715

1816
quote! {
1917
#[linkme::distributed_slice(intertrait::CASTERS)]
20-
static #static_var: fn() -> (std::any::TypeId, intertrait::BoxedCaster) = #fn_ident;
21-
2218
fn #fn_ident() -> (std::any::TypeId, intertrait::BoxedCaster) {
2319
let type_id = std::any::TypeId::of::<#ty>();
2420
let caster = Box::new(intertrait::Caster::<dyn #trait_> {
@@ -31,20 +27,9 @@ pub fn generate_caster(ty: &impl ToTokens, trait_: &Path) -> TokenStream {
3127
}
3228
}
3329

34-
const STATIC_PREFIX: &[u8] = b"__";
35-
const STATIC_BUF_LEN: usize = STATIC_PREFIX.len() + Simple::LENGTH;
36-
3730
const FN_PREFIX: &[u8] = b"__";
3831
const FN_BUF_LEN: usize = FN_PREFIX.len() + Simple::LENGTH;
3932

40-
fn generate_static(buf: &mut [u8]) -> &str {
41-
buf[..STATIC_PREFIX.len()].copy_from_slice(STATIC_PREFIX);
42-
Uuid::new_v4()
43-
.to_simple()
44-
.encode_upper(&mut buf[STATIC_PREFIX.len()..]);
45-
unsafe { from_utf8_unchecked(&buf[..STATIC_BUF_LEN]) }
46-
}
47-
4833
fn generate_fn(buf: &mut [u8]) -> &str {
4934
buf[..FN_PREFIX.len()].copy_from_slice(FN_PREFIX);
5035
Uuid::new_v4()

0 commit comments

Comments
 (0)