@@ -87,7 +87,15 @@ impl Default for ClientOptions {
87
87
}
88
88
89
89
lazy_static ! {
90
- static ref CRATE_RE : Regex = Regex :: new( r"^([a-zA-Z0-9_]+?)::" ) . unwrap( ) ;
90
+ static ref CRATE_RE : Regex = Regex :: new( r"^(?:_<)?([a-zA-Z0-9_]+?)(?:\.\.|::)" ) . unwrap( ) ;
91
+ }
92
+
93
+ /// Tries to parse the rust crate from a function name.
94
+ fn parse_crate_name ( func_name : & str ) -> Option < String > {
95
+ CRATE_RE
96
+ . captures ( func_name)
97
+ . and_then ( |caps| caps. get ( 1 ) )
98
+ . map ( |cr| cr. as_str ( ) . into ( ) )
91
99
}
92
100
93
101
/// Helper trait to convert an object into a client config
@@ -356,10 +364,7 @@ impl Client {
356
364
357
365
// set package if missing to crate prefix
358
366
if frame. package . is_none ( ) {
359
- frame. package = CRATE_RE
360
- . captures ( func_name)
361
- . and_then ( |caps| caps. get ( 1 ) )
362
- . map ( |cr| cr. as_str ( ) . into ( ) ) ;
367
+ frame. package = parse_crate_name ( func_name) ;
363
368
}
364
369
365
370
match frame. in_app {
@@ -499,3 +504,32 @@ pub fn init<C: IntoClientConfig>(cfg: C) -> ClientInitGuard {
499
504
client
500
505
} ) )
501
506
}
507
+
508
+ #[ cfg( test) ]
509
+ mod tests {
510
+ use super :: * ;
511
+
512
+ #[ test]
513
+ fn test_parse_crate_name ( ) {
514
+ assert_eq ! (
515
+ parse_crate_name( "futures::task_impl::std::set" ) ,
516
+ Some ( "futures" . into( ) )
517
+ ) ;
518
+ }
519
+
520
+ #[ test]
521
+ fn test_parse_crate_name_impl ( ) {
522
+ assert_eq ! (
523
+ parse_crate_name( "_<futures..task_impl..Spawn<T>>::enter::_{{closure}}" ) ,
524
+ Some ( "futures" . into( ) )
525
+ ) ;
526
+ }
527
+
528
+ #[ test]
529
+ fn test_parse_crate_name_unknown ( ) {
530
+ assert_eq ! (
531
+ parse_crate_name( "_<F as alloc..boxed..FnBox<A>>::call_box" ) ,
532
+ None
533
+ ) ;
534
+ }
535
+ }
0 commit comments