abi_stable_shared/
lib.rs

1#[doc(hidden)]
2#[macro_use]
3pub mod test_utils;
4
5pub mod const_utils;
6
7#[doc(hidden)]
8pub mod type_layout {
9    pub mod small_types;
10    pub mod tl_field_accessor_macro;
11    pub mod tl_field_macro;
12    pub mod tl_lifetimes_macro;
13    pub mod tl_multi_tl_macro;
14    pub mod tl_type_layout_index;
15}
16
17use core_extensions::StringExt;
18
19/// The name mangling scheme of `abi_stable`.
20#[doc(hidden)]
21pub fn mangle_ident<S>(kind: &str, name: S) -> String
22where
23    S: ::std::fmt::Display,
24{
25    let unmangled = format!("_as.{}.{}", kind, name);
26
27    let mut mangled = String::with_capacity(unmangled.len() * 3 / 2);
28
29    for kv in unmangled.split_while(|c| c.is_alphanumeric()) {
30        if kv.key {
31            mangled.push_str(kv.str);
32            continue;
33        }
34        for c in kv.str.chars() {
35            mangled.push_str(match c {
36                '.' => "_0",
37                '_' => "_1",
38                '-' => "_2",
39                '<' => "_3",
40                '>' => "_4",
41                '(' => "_5",
42                ')' => "_6",
43                '[' => "_7",
44                ']' => "_8",
45                '{' => "_9",
46                '}' => "_a",
47                ' ' => "_b",
48                ',' => "_c",
49                ':' => "_d",
50                ';' => "_e",
51                '!' => "_f",
52                '#' => "_g",
53                '$' => "_h",
54                '%' => "_i",
55                '/' => "_j",
56                '=' => "_k",
57                '?' => "_l",
58                '¿' => "_m",
59                '¡' => "_o",
60                '*' => "_p",
61                '+' => "_q",
62                '~' => "_r",
63                '|' => "_s",
64                '°' => "_t",
65                '¬' => "_u",
66                '\'' => "_x",
67                '\"' => "_y",
68                '`' => "_z",
69                c => panic!("cannot currently mangle the '{}' character.", c),
70            });
71        }
72    }
73
74    mangled
75}
76
77/// Gets the name of the static that contains the LibHeader of an abi_stable library.
78///
79/// This does not have a trailing `'\0'`,
80/// you need to append it to pass the name to C APIs.
81pub fn mangled_root_module_loader_name() -> String {
82    mangle_ident("lib_header", "root module loader")
83}