@@ -210,47 +210,44 @@ pub struct TsconfigOptions {
210210 pub references : Option < Either < String , Vec < String > > > ,
211211}
212212
213- impl Into < rspack_resolver :: Restriction > for Restriction {
214- fn into ( self ) -> rspack_resolver :: Restriction {
215- match ( self . path , self . regex ) {
213+ impl From < Restriction > for rspack_resolver :: Restriction {
214+ fn from ( r : Restriction ) -> Self {
215+ match ( r . path , r . regex ) {
216216 ( None , None ) => {
217217 panic ! ( "Should specify path or regex" )
218218 }
219219 ( None , Some ( regex) ) => {
220- let re = Regex :: new ( & regex) . unwrap ( ) ;
221-
222- rspack_resolver:: Restriction :: Fn ( Arc :: new ( move |path| {
223- re. is_match ( path. to_str ( ) . unwrap_or_default ( ) )
224- } ) )
220+ let re = Regex :: new ( & regex) . expect ( & format ! ( "Invalid regex pattern: {}" , regex) ) ;
221+ Self :: Fn ( Arc :: new ( move |path| re. is_match ( path. to_str ( ) . unwrap_or_default ( ) ) ) )
225222 }
226- ( Some ( path) , None ) => rspack_resolver :: Restriction :: Path ( PathBuf :: from ( path) ) ,
223+ ( Some ( path) , None ) => Self :: Path ( PathBuf :: from ( path) ) ,
227224 ( Some ( _) , Some ( _) ) => {
228225 panic ! ( "Restriction can't be path and regex at the same time" )
229226 }
230227 }
231228 }
232229}
233230
234- impl Into < rspack_resolver :: EnforceExtension > for EnforceExtension {
235- fn into ( self ) -> rspack_resolver :: EnforceExtension {
236- match self {
237- EnforceExtension :: Auto => rspack_resolver :: EnforceExtension :: Auto ,
238- EnforceExtension :: Enabled => rspack_resolver :: EnforceExtension :: Enabled ,
239- EnforceExtension :: Disabled => rspack_resolver :: EnforceExtension :: Disabled ,
231+ impl From < EnforceExtension > for rspack_resolver :: EnforceExtension {
232+ fn from ( extension : EnforceExtension ) -> Self {
233+ match extension {
234+ EnforceExtension :: Auto => Self :: Auto ,
235+ EnforceExtension :: Enabled => Self :: Enabled ,
236+ EnforceExtension :: Disabled => Self :: Disabled ,
240237 }
241238 }
242239}
243240
244- impl Into < rspack_resolver :: TsconfigOptions > for TsconfigOptions {
245- fn into ( self ) -> rspack_resolver :: TsconfigOptions {
246- rspack_resolver :: TsconfigOptions {
247- config_file : PathBuf :: from ( self . config_file ) ,
248- references : match self . references {
241+ impl From < TsconfigOptions > for rspack_resolver :: TsconfigOptions {
242+ fn from ( options : TsconfigOptions ) -> Self {
243+ Self {
244+ config_file : PathBuf :: from ( options . config_file ) ,
245+ references : match options . references {
249246 Some ( Either :: A ( string) ) if string. as_str ( ) == "auto" => {
250247 rspack_resolver:: TsconfigReferences :: Auto
251248 }
252249 Some ( Either :: A ( opt) ) => {
253- panic ! ( "`{}` is not a valid option for tsconfig references" , opt )
250+ panic ! ( "`{opt }` is not a valid option for tsconfig references" )
254251 }
255252 Some ( Either :: B ( paths) ) => rspack_resolver:: TsconfigReferences :: Paths (
256253 paths. into_iter ( ) . map ( PathBuf :: from) . collect :: < Vec < _ > > ( ) ,
@@ -264,9 +261,9 @@ impl Into<rspack_resolver::TsconfigOptions> for TsconfigOptions {
264261type StrOrStrListType = Either < String , Vec < String > > ;
265262pub struct StrOrStrList ( pub StrOrStrListType ) ;
266263
267- impl Into < Vec < String > > for StrOrStrList {
268- fn into ( self ) -> Vec < String > {
269- match self {
264+ impl From < StrOrStrList > for Vec < String > {
265+ fn from ( value : StrOrStrList ) -> Self {
266+ match value {
270267 StrOrStrList ( Either :: A ( s) ) => Vec :: from ( [ s] ) ,
271268 StrOrStrList ( Either :: B ( a) ) => a,
272269 }
0 commit comments