1- use std:: fmt:: Debug ;
1+ use std:: {
2+ fmt:: Debug ,
3+ path:: { Path , PathBuf } ,
4+ } ;
25
36use crate :: {
47 protocol:: {
@@ -23,7 +26,7 @@ pub struct Options {
2326 /// https://sass-lang.com/documentation/js-api/interfaces/Options#importers
2427 pub importers : Vec < SassImporter > ,
2528 /// https://sass-lang.com/documentation/js-api/interfaces/Options#loadPaths
26- pub load_paths : Vec < String > ,
29+ pub load_paths : Vec < PathBuf > ,
2730 /// https://sass-lang.com/documentation/js-api/interfaces/Options#logger
2831 pub logger : Option < SassLogger > ,
2932 /// https://sass-lang.com/documentation/js-api/interfaces/Options#quietDeps
@@ -82,13 +85,14 @@ impl OptionsBuilder {
8285 self
8386 }
8487
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 ( ) ;
8791 self
8892 }
8993
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 ( ) ) ;
9296 self
9397 }
9498
@@ -134,28 +138,24 @@ impl OptionsBuilder {
134138
135139 pub fn sass_importers (
136140 mut self ,
137- arg : impl IntoIterator < Item = SassImporter > ,
141+ arg : impl IntoIterator < Item = impl Into < SassImporter > > ,
138142 ) -> Self {
139- self . options . importers = arg. into_iter ( ) . collect ( ) ;
143+ self . options . importers = arg. into_iter ( ) . map ( |i| i . into ( ) ) . collect ( ) ;
140144 self
141145 }
142146
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 {
144148 self
145149 . options
146150 . importers
147- . push ( SassImporter :: Importer ( arg . into ( ) ) ) ;
151+ . push ( SassImporter :: Importer ( Box :: new ( arg ) as Box < dyn Importer > ) ) ;
148152 self
149153 }
150154
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+ ) ) ;
159159 self
160160 }
161161}
@@ -201,16 +201,16 @@ impl StringOptionsBuilder {
201201 self
202202 }
203203
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 ) ) ) ;
206206 self
207207 }
208208
209- pub fn input_file_importer (
209+ pub fn input_file_importer < I : ' static + FileImporter > (
210210 mut self ,
211- arg : impl Into < Box < dyn FileImporter > > ,
211+ arg : I ,
212212 ) -> Self {
213- self . input_importer = Some ( SassImporter :: FileImporter ( arg . into ( ) ) ) ;
213+ self . input_importer = Some ( SassImporter :: FileImporter ( Box :: new ( arg ) ) ) ;
214214 self
215215 }
216216
@@ -234,13 +234,14 @@ impl StringOptionsBuilder {
234234 self
235235 }
236236
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 ( ) ;
239240 self
240241 }
241242
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 ( ) ) ;
244245 self
245246 }
246247
@@ -286,28 +287,25 @@ impl StringOptionsBuilder {
286287
287288 pub fn sass_importers (
288289 mut self ,
289- arg : impl IntoIterator < Item = SassImporter > ,
290+ arg : impl IntoIterator < Item = impl Into < SassImporter > > ,
290291 ) -> Self {
291- self . options . importers = arg. into_iter ( ) . collect ( ) ;
292+ self . options . importers = arg. into_iter ( ) . map ( |i| i . into ( ) ) . collect ( ) ;
292293 self
293294 }
294295
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 {
296297 self
297298 . options
298299 . importers
299- . push ( SassImporter :: Importer ( arg . into ( ) ) ) ;
300+ . push ( SassImporter :: Importer ( Box :: new ( arg ) ) ) ;
300301 self
301302 }
302303
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 {
307305 self
308306 . options
309307 . importers
310- . push ( SassImporter :: FileImporter ( arg . into ( ) ) ) ;
308+ . push ( SassImporter :: FileImporter ( Box :: new ( arg ) ) ) ;
311309 self
312310 }
313311}
@@ -368,7 +366,7 @@ pub struct ImporterResult {
368366 /// https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#contents
369367 pub contents : String ,
370368 /// https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#sourceMapUrl
371- pub source_map_url : Option < String > ,
369+ pub source_map_url : Option < Url > ,
372370 /// https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#syntax
373371 pub syntax : Syntax ,
374372}
@@ -379,7 +377,7 @@ pub struct CompileResult {
379377 /// https://sass-lang.com/documentation/js-api/interfaces/CompileResult#css
380378 pub css : String ,
381379 /// https://sass-lang.com/documentation/js-api/interfaces/CompileResult#loadedUrls
382- pub loaded_urls : Vec < String > ,
380+ pub loaded_urls : Vec < Url > ,
383381 /// https://sass-lang.com/documentation/js-api/interfaces/CompileResult#sourceMap
384382 pub source_map : Option < String > ,
385383}
@@ -402,7 +400,11 @@ impl From<CompileSuccess> for CompileResult {
402400 fn from ( s : CompileSuccess ) -> Self {
403401 Self {
404402 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 ( ) ,
406408 source_map : if s. source_map . is_empty ( ) {
407409 None
408410 } else {
0 commit comments