@@ -19,18 +19,16 @@ able to parse any URI, such as `urn:isbn:0451450523`.
19
19
#[ macro_use]
20
20
extern crate bitflags;
21
21
22
- use serde:: { Deserialize , Serialize } ;
23
- use std:: fmt:: Debug ;
24
- pub use url:: Url ;
25
-
26
- use std:: collections:: HashMap ;
22
+ use std:: { collections:: HashMap , fmt:: Debug } ;
27
23
28
- use serde:: de;
29
- use serde:: de:: Error as Error_ ;
24
+ use serde:: { de, de:: Error as Error_ , Deserialize , Serialize } ;
30
25
use serde_json:: Value ;
26
+ pub use url:: Url ;
31
27
32
- const fn fmt_pascal_case_const ( name : & str ) -> ( [ u8 ; 128 ] , usize ) {
33
- let mut buf = [ 0 ; 128 ] ;
28
+ // Large enough to contain any enumeration name defined in this crate
29
+ type PascalCaseBuf = [ u8 ; 32 ] ;
30
+ const fn fmt_pascal_case_const ( name : & str ) -> ( PascalCaseBuf , usize ) {
31
+ let mut buf = [ 0 ; 32 ] ;
34
32
let mut buf_i = 0 ;
35
33
let mut name_i = 0 ;
36
34
let name = name. as_bytes ( ) ;
@@ -90,9 +88,13 @@ macro_rules! lsp_enum {
90
88
impl std:: convert:: TryFrom <& str > for $typ {
91
89
type Error = & ' static str ;
92
90
fn try_from( value: & str ) -> Result <Self , Self :: Error > {
93
- match value {
91
+ match ( ) {
94
92
$(
95
- _ if { let ( buf, len) = crate :: fmt_pascal_case_const( stringify!( $name) ) ; & buf[ ..len] == value. as_bytes( ) } => Ok ( Self :: $name) ,
93
+ _ if {
94
+ const X : ( crate :: PascalCaseBuf , usize ) = crate :: fmt_pascal_case_const( stringify!( $name) ) ;
95
+ let ( buf, len) = X ;
96
+ & buf[ ..len] == value. as_bytes( )
97
+ } => Ok ( Self :: $name) ,
96
98
) *
97
99
_ => Err ( "unknown enum variant" ) ,
98
100
}
@@ -706,10 +708,10 @@ pub struct ConfigurationItem {
706
708
}
707
709
708
710
mod url_map {
709
- use super :: * ;
710
-
711
711
use std:: fmt;
712
712
713
+ use super :: * ;
714
+
713
715
pub fn deserialize < ' de , D > (
714
716
deserializer : D ,
715
717
) -> Result < Option < HashMap < Url , Vec < TextEdit > > > , D :: Error >
@@ -2453,9 +2455,10 @@ impl SymbolTag {
2453
2455
2454
2456
#[ cfg( test) ]
2455
2457
mod tests {
2456
- use super :: * ;
2457
2458
use serde:: { Deserialize , Serialize } ;
2458
2459
2460
+ use super :: * ;
2461
+
2459
2462
pub ( crate ) fn test_serialization < SER > ( ms : & SER , expected : & str )
2460
2463
where
2461
2464
SER : Serialize + for < ' de > Deserialize < ' de > + PartialEq + std:: fmt:: Debug ,
0 commit comments