13
13
//! [`ThemeSet`]: ../highlighting/struct.ThemeSet.html
14
14
//! [`dump_to_file`]: fn.dump_to_file.html
15
15
use bincode:: Result ;
16
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
16
+ #[ cfg( feature = "dump-load" ) ]
17
17
use bincode:: deserialize_from;
18
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
18
+ #[ cfg( feature = "dump-create" ) ]
19
19
use bincode:: serialize_into;
20
20
use std:: fs:: File ;
21
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
21
+ #[ cfg( feature = "dump-load" ) ]
22
22
use std:: io:: { BufRead } ;
23
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
23
+ #[ cfg( feature = "dump-create" ) ]
24
24
use std:: io:: { BufWriter , Write } ;
25
- #[ cfg( all( feature = "parsing" , feature = "assets" , any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ) ]
25
+ #[ cfg( all( feature = "parsing" , feature = "assets" , feature = "dump-load" ) ) ]
26
26
use crate :: parsing:: SyntaxSet ;
27
- #[ cfg( all( feature = "assets" , any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ) ]
27
+ #[ cfg( all( feature = "assets" , feature = "dump-load" ) ) ]
28
28
use crate :: highlighting:: ThemeSet ;
29
29
use std:: path:: Path ;
30
30
#[ cfg( feature = "dump-create" ) ]
31
31
use flate2:: write:: ZlibEncoder ;
32
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
32
+ #[ cfg( feature = "dump-load" ) ]
33
33
use flate2:: bufread:: ZlibDecoder ;
34
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
34
+ #[ cfg( feature = "dump-create" ) ]
35
35
use flate2:: Compression ;
36
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
36
+ #[ cfg( feature = "dump-create" ) ]
37
37
use serde:: Serialize ;
38
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
38
+ #[ cfg( feature = "dump-load" ) ]
39
39
use serde:: de:: DeserializeOwned ;
40
40
41
41
/// Dumps an object to the given writer in a compressed binary format
42
42
///
43
43
/// The writer is encoded with the `bincode` crate and compressed with `flate2`.
44
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
44
+ #[ cfg( feature = "dump-create" ) ]
45
45
pub fn dump_to_writer < T : Serialize , W : Write > ( to_dump : & T , output : W ) -> Result < ( ) > {
46
46
serialize_to_writer_impl ( to_dump, output, true )
47
47
}
48
48
49
49
/// Dumps an object to a binary array in the same format as [`dump_to_writer`]
50
50
///
51
51
/// [`dump_to_writer`]: fn.dump_to_writer.html
52
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
52
+ #[ cfg( feature = "dump-create" ) ]
53
53
pub fn dump_binary < T : Serialize > ( o : & T ) -> Vec < u8 > {
54
54
let mut v = Vec :: new ( ) ;
55
55
dump_to_writer ( o, & mut v) . unwrap ( ) ;
@@ -62,28 +62,28 @@ pub fn dump_binary<T: Serialize>(o: &T) -> Vec<u8> {
62
62
/// the `bincode` crate and then compressed with the `flate2` crate.
63
63
///
64
64
/// [`dump_to_writer`]: fn.dump_to_writer.html
65
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
65
+ #[ cfg( feature = "dump-create" ) ]
66
66
pub fn dump_to_file < T : Serialize , P : AsRef < Path > > ( o : & T , path : P ) -> Result < ( ) > {
67
67
let out = BufWriter :: new ( File :: create ( path) ?) ;
68
68
dump_to_writer ( o, out)
69
69
}
70
70
71
71
/// A helper function for decoding and decompressing data from a reader
72
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
72
+ #[ cfg( feature = "dump-load" ) ]
73
73
pub fn from_reader < T : DeserializeOwned , R : BufRead > ( input : R ) -> Result < T > {
74
74
deserialize_from_reader_impl ( input, true )
75
75
}
76
76
77
77
/// Returns a fully loaded object from a binary dump.
78
78
///
79
79
/// This function panics if the dump is invalid.
80
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
80
+ #[ cfg( feature = "dump-load" ) ]
81
81
pub fn from_binary < T : DeserializeOwned > ( v : & [ u8 ] ) -> T {
82
82
from_reader ( v) . unwrap ( )
83
83
}
84
84
85
85
/// Returns a fully loaded object from a binary dump file.
86
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
86
+ #[ cfg( feature = "dump-load" ) ]
87
87
pub fn from_dump_file < T : DeserializeOwned , P : AsRef < Path > > ( path : P ) -> Result < T > {
88
88
let contents = std:: fs:: read ( path) ?;
89
89
from_reader ( & contents[ ..] )
@@ -93,15 +93,15 @@ pub fn from_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T>
93
93
/// itself shall not be compressed, because the data for its lazy-loaded
94
94
/// syntaxes are already compressed. Compressing another time just results in
95
95
/// bad performance.
96
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
96
+ #[ cfg( feature = "dump-create" ) ]
97
97
pub fn dump_to_uncompressed_file < T : Serialize , P : AsRef < Path > > ( o : & T , path : P ) -> Result < ( ) > {
98
98
let out = BufWriter :: new ( File :: create ( path) ?) ;
99
99
serialize_to_writer_impl ( o, out, false )
100
100
}
101
101
102
102
/// To be used when deserializing a [`SyntaxSet`] that was previously written to
103
103
/// file using [dump_to_uncompressed_file].
104
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
104
+ #[ cfg( feature = "dump-load" ) ]
105
105
pub fn from_uncompressed_dump_file < T : DeserializeOwned , P : AsRef < Path > > ( path : P ) -> Result < T > {
106
106
let contents = std:: fs:: read ( path) ?;
107
107
deserialize_from_reader_impl ( & contents[ ..] , false )
@@ -110,13 +110,13 @@ pub fn from_uncompressed_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P)
110
110
/// To be used when deserializing a [`SyntaxSet`] from raw data, for example
111
111
/// data that has been embedded in your own binary with the [`include_bytes!`]
112
112
/// macro.
113
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
113
+ #[ cfg( feature = "dump-load" ) ]
114
114
pub fn from_uncompressed_data < T : DeserializeOwned > ( v : & [ u8 ] ) -> Result < T > {
115
115
deserialize_from_reader_impl ( v, false )
116
116
}
117
117
118
118
/// Private low level helper function used to implement the public API.
119
- #[ cfg( any ( feature = "dump-create" , feature = "dump-create-rs" ) ) ]
119
+ #[ cfg( feature = "dump-create" ) ]
120
120
fn serialize_to_writer_impl < T : Serialize , W : Write > ( to_dump : & T , output : W , use_compression : bool ) -> Result < ( ) > {
121
121
if use_compression {
122
122
let mut encoder = ZlibEncoder :: new ( output, Compression :: best ( ) ) ;
@@ -127,7 +127,7 @@ fn serialize_to_writer_impl<T: Serialize, W: Write>(to_dump: &T, output: W, use_
127
127
}
128
128
129
129
/// Private low level helper function used to implement the public API.
130
- #[ cfg( any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ]
130
+ #[ cfg( feature = "dump-load" ) ]
131
131
fn deserialize_from_reader_impl < T : DeserializeOwned , R : BufRead > ( input : R , use_compression : bool ) -> Result < T > {
132
132
if use_compression {
133
133
let mut decoder = ZlibDecoder :: new ( input) ;
@@ -137,7 +137,7 @@ fn deserialize_from_reader_impl<T: DeserializeOwned, R: BufRead>(input: R, use_c
137
137
}
138
138
}
139
139
140
- #[ cfg( all( feature = "parsing" , feature = "assets" , any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ) ]
140
+ #[ cfg( all( feature = "parsing" , feature = "assets" , feature = "dump-load" ) ) ]
141
141
impl SyntaxSet {
142
142
/// Instantiates a new syntax set from a binary dump of Sublime Text's default open source
143
143
/// syntax definitions.
@@ -195,7 +195,7 @@ impl SyntaxSet {
195
195
}
196
196
}
197
197
198
- #[ cfg( all( feature = "assets" , any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ) ]
198
+ #[ cfg( all( feature = "assets" , feature = "dump-load" ) ) ]
199
199
impl ThemeSet {
200
200
/// Loads the set of default themes
201
201
/// Currently includes (these are the keys for the map):
@@ -210,7 +210,7 @@ impl ThemeSet {
210
210
211
211
#[ cfg( test) ]
212
212
mod tests {
213
- #[ cfg( all( feature = "yaml-load" , any ( feature = "dump-create" , feature = "dump-create-rs" ) , any ( feature = "dump- load", feature = "dump-load-rs" ) ) ) ]
213
+ #[ cfg( all( feature = "yaml-load" , feature = "dump-create" , feature = "dump-load" ) ) ]
214
214
#[ test]
215
215
fn can_dump_and_load ( ) {
216
216
use super :: * ;
@@ -225,7 +225,7 @@ mod tests {
225
225
assert_eq ! ( ss. syntaxes( ) . len( ) , ss2. syntaxes( ) . len( ) ) ;
226
226
}
227
227
228
- #[ cfg( all( feature = "yaml-load" , any ( feature = "dump-create" , feature = "dump-create-rs" ) , any ( feature = "dump- load", feature = "dump-load-rs" ) ) ) ]
228
+ #[ cfg( all( feature = "yaml-load" , feature = "dump-create" , feature = "dump-load" ) ) ]
229
229
#[ test]
230
230
fn dump_is_deterministic ( ) {
231
231
use super :: * ;
@@ -246,7 +246,7 @@ mod tests {
246
246
assert_eq ! ( bin1, bin2) ;
247
247
}
248
248
249
- #[ cfg( all( feature = "assets" , any ( feature = "dump-load" , feature = "dump-load-rs" ) ) ) ]
249
+ #[ cfg( all( feature = "assets" , feature = "dump-load" ) ) ]
250
250
#[ test]
251
251
fn has_default_themes ( ) {
252
252
use crate :: highlighting:: ThemeSet ;
0 commit comments