File tree 3 files changed +26
-2
lines changed
3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ cfg_if! {
40
40
}
41
41
} )
42
42
}
43
+
44
+ fn unintern_str( key: & str ) {
45
+ CACHE . with( |cache| {
46
+ let mut cache = cache. entries. borrow_mut( ) ;
47
+
48
+ cache. remove( key) ;
49
+ } )
50
+ }
43
51
}
44
52
}
45
53
@@ -80,3 +88,16 @@ pub fn intern(s: &str) -> &str {
80
88
81
89
s
82
90
}
91
+
92
+
93
+ /// Removes a Rust string from the intern cache.
94
+ ///
95
+ /// This does the opposite of the [`intern`](fn.intern.html) function.
96
+ ///
97
+ /// If the [`intern`](fn.intern.html) function is called again then it will re-intern the string.
98
+ #[ allow( unused_variables) ]
99
+ #[ inline]
100
+ pub fn unintern ( s : & str ) {
101
+ #[ cfg( feature = "enable-interning" ) ]
102
+ unintern_str ( s) ;
103
+ }
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ if_std! {
70
70
mod anyref;
71
71
72
72
mod cache;
73
- pub use cache:: intern:: intern;
73
+ pub use cache:: intern:: { intern, unintern } ;
74
74
}
75
75
76
76
/// Representation of an object owned by JS.
Original file line number Diff line number Diff line change 1
1
use wasm_bindgen:: prelude:: * ;
2
- use wasm_bindgen:: JsCast ;
2
+ use wasm_bindgen:: { JsCast , intern , unintern } ;
3
3
use wasm_bindgen_test:: * ;
4
4
5
5
#[ wasm_bindgen( module = "tests/wasm/simple.js" ) ]
@@ -157,6 +157,9 @@ fn binding_to_unimplemented_apis_doesnt_break_everything() {
157
157
fn optional_slices ( ) {
158
158
optional_str_none ( None ) ;
159
159
optional_str_some ( Some ( "x" ) ) ;
160
+ optional_str_some ( Some ( intern ( "x" ) ) ) ;
161
+ unintern ( "x" ) ;
162
+ optional_str_some ( Some ( "x" ) ) ;
160
163
optional_slice_none ( None ) ;
161
164
optional_slice_some ( Some ( & [ 1 , 2 , 3 ] ) ) ;
162
165
optional_string_none ( None ) ;
You can’t perform that action at this time.
0 commit comments