1
- use std:: fmt:: Debug ;
1
+ use std:: {
2
+ fmt:: Debug ,
3
+ path:: { Path , PathBuf } ,
4
+ } ;
2
5
3
6
use crate :: {
4
7
protocol:: {
@@ -23,7 +26,7 @@ pub struct Options {
23
26
/// https://sass-lang.com/documentation/js-api/interfaces/Options#importers
24
27
pub importers : Vec < SassImporter > ,
25
28
/// https://sass-lang.com/documentation/js-api/interfaces/Options#loadPaths
26
- pub load_paths : Vec < String > ,
29
+ pub load_paths : Vec < PathBuf > ,
27
30
/// https://sass-lang.com/documentation/js-api/interfaces/Options#logger
28
31
pub logger : Option < SassLogger > ,
29
32
/// https://sass-lang.com/documentation/js-api/interfaces/Options#quietDeps
@@ -82,13 +85,14 @@ impl OptionsBuilder {
82
85
self
83
86
}
84
87
85
- pub fn load_paths ( mut self , arg : impl IntoIterator < Item = String > ) -> Self {
86
- self . options . load_paths = arg. into_iter ( ) . collect ( ) ;
88
+ pub fn load_paths ( mut self , arg : & [ impl AsRef < Path > ] ) -> Self {
89
+ self . options . load_paths =
90
+ arg. iter ( ) . map ( |p| p. as_ref ( ) . to_owned ( ) ) . collect ( ) ;
87
91
self
88
92
}
89
93
90
- pub fn load_path ( mut self , arg : impl Into < String > ) -> Self {
91
- self . options . load_paths . push ( arg. into ( ) ) ;
94
+ pub fn load_path ( mut self , arg : impl AsRef < Path > ) -> Self {
95
+ self . options . load_paths . push ( arg. as_ref ( ) . to_owned ( ) ) ;
92
96
self
93
97
}
94
98
@@ -134,28 +138,24 @@ impl OptionsBuilder {
134
138
135
139
pub fn sass_importers (
136
140
mut self ,
137
- arg : impl IntoIterator < Item = SassImporter > ,
141
+ arg : impl IntoIterator < Item = impl Into < SassImporter > > ,
138
142
) -> Self {
139
- self . options . importers = arg. into_iter ( ) . collect ( ) ;
143
+ self . options . importers = arg. into_iter ( ) . map ( |i| i . into ( ) ) . collect ( ) ;
140
144
self
141
145
}
142
146
143
- pub fn importer ( mut self , arg : impl Into < Box < dyn Importer > > ) -> Self {
147
+ pub fn importer < I : ' static + Importer > ( mut self , arg : I ) -> Self {
144
148
self
145
149
. options
146
150
. importers
147
- . push ( SassImporter :: Importer ( arg . into ( ) ) ) ;
151
+ . push ( SassImporter :: Importer ( Box :: new ( arg ) as Box < dyn Importer > ) ) ;
148
152
self
149
153
}
150
154
151
- pub fn file_importer (
152
- mut self ,
153
- arg : impl Into < Box < dyn FileImporter > > ,
154
- ) -> Self {
155
- self
156
- . options
157
- . importers
158
- . push ( SassImporter :: FileImporter ( arg. into ( ) ) ) ;
155
+ pub fn file_importer < I : ' static + FileImporter > ( mut self , arg : I ) -> Self {
156
+ self . options . importers . push ( SassImporter :: FileImporter (
157
+ Box :: new ( arg) as Box < dyn FileImporter >
158
+ ) ) ;
159
159
self
160
160
}
161
161
}
@@ -201,16 +201,16 @@ impl StringOptionsBuilder {
201
201
self
202
202
}
203
203
204
- pub fn input_importer ( mut self , arg : impl Into < Box < dyn Importer > > ) -> Self {
205
- self . input_importer = Some ( SassImporter :: Importer ( arg . into ( ) ) ) ;
204
+ pub fn input_importer < I : ' static + Importer > ( mut self , arg : I ) -> Self {
205
+ self . input_importer = Some ( SassImporter :: Importer ( Box :: new ( arg ) ) ) ;
206
206
self
207
207
}
208
208
209
- pub fn input_file_importer (
209
+ pub fn input_file_importer < I : ' static + FileImporter > (
210
210
mut self ,
211
- arg : impl Into < Box < dyn FileImporter > > ,
211
+ arg : I ,
212
212
) -> Self {
213
- self . input_importer = Some ( SassImporter :: FileImporter ( arg . into ( ) ) ) ;
213
+ self . input_importer = Some ( SassImporter :: FileImporter ( Box :: new ( arg ) ) ) ;
214
214
self
215
215
}
216
216
@@ -234,13 +234,14 @@ impl StringOptionsBuilder {
234
234
self
235
235
}
236
236
237
- pub fn load_paths ( mut self , arg : impl IntoIterator < Item = String > ) -> Self {
238
- self . options . load_paths = arg. into_iter ( ) . collect ( ) ;
237
+ pub fn load_paths ( mut self , arg : & [ impl AsRef < Path > ] ) -> Self {
238
+ self . options . load_paths =
239
+ arg. iter ( ) . map ( |p| p. as_ref ( ) . to_owned ( ) ) . collect ( ) ;
239
240
self
240
241
}
241
242
242
- pub fn load_path ( mut self , arg : impl Into < String > ) -> Self {
243
- self . options . load_paths . push ( arg. into ( ) ) ;
243
+ pub fn load_path ( mut self , arg : impl AsRef < Path > ) -> Self {
244
+ self . options . load_paths . push ( arg. as_ref ( ) . to_owned ( ) ) ;
244
245
self
245
246
}
246
247
@@ -286,28 +287,25 @@ impl StringOptionsBuilder {
286
287
287
288
pub fn sass_importers (
288
289
mut self ,
289
- arg : impl IntoIterator < Item = SassImporter > ,
290
+ arg : impl IntoIterator < Item = impl Into < SassImporter > > ,
290
291
) -> Self {
291
- self . options . importers = arg. into_iter ( ) . collect ( ) ;
292
+ self . options . importers = arg. into_iter ( ) . map ( |i| i . into ( ) ) . collect ( ) ;
292
293
self
293
294
}
294
295
295
- pub fn importer ( mut self , arg : impl Into < Box < dyn Importer > > ) -> Self {
296
+ pub fn importer < I : ' static + Importer > ( mut self , arg : I ) -> Self {
296
297
self
297
298
. options
298
299
. importers
299
- . push ( SassImporter :: Importer ( arg . into ( ) ) ) ;
300
+ . push ( SassImporter :: Importer ( Box :: new ( arg ) ) ) ;
300
301
self
301
302
}
302
303
303
- pub fn file_importer (
304
- mut self ,
305
- arg : impl Into < Box < dyn FileImporter > > ,
306
- ) -> Self {
304
+ pub fn file_importer < I : ' static + FileImporter > ( mut self , arg : I ) -> Self {
307
305
self
308
306
. options
309
307
. importers
310
- . push ( SassImporter :: FileImporter ( arg . into ( ) ) ) ;
308
+ . push ( SassImporter :: FileImporter ( Box :: new ( arg ) ) ) ;
311
309
self
312
310
}
313
311
}
@@ -368,7 +366,7 @@ pub struct ImporterResult {
368
366
/// https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#contents
369
367
pub contents : String ,
370
368
/// https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#sourceMapUrl
371
- pub source_map_url : Option < String > ,
369
+ pub source_map_url : Option < Url > ,
372
370
/// https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#syntax
373
371
pub syntax : Syntax ,
374
372
}
@@ -379,7 +377,7 @@ pub struct CompileResult {
379
377
/// https://sass-lang.com/documentation/js-api/interfaces/CompileResult#css
380
378
pub css : String ,
381
379
/// https://sass-lang.com/documentation/js-api/interfaces/CompileResult#loadedUrls
382
- pub loaded_urls : Vec < String > ,
380
+ pub loaded_urls : Vec < Url > ,
383
381
/// https://sass-lang.com/documentation/js-api/interfaces/CompileResult#sourceMap
384
382
pub source_map : Option < String > ,
385
383
}
@@ -402,7 +400,11 @@ impl From<CompileSuccess> for CompileResult {
402
400
fn from ( s : CompileSuccess ) -> Self {
403
401
Self {
404
402
css : s. css ,
405
- loaded_urls : s. loaded_urls ,
403
+ loaded_urls : s
404
+ . loaded_urls
405
+ . iter ( )
406
+ . map ( |url| Url :: parse ( url) . unwrap ( ) )
407
+ . collect ( ) ,
406
408
source_map : if s. source_map . is_empty ( ) {
407
409
None
408
410
} else {
0 commit comments