@@ -49,6 +49,13 @@ pub struct Remapping {
49
49
pub path : String ,
50
50
}
51
51
52
+ impl Remapping {
53
+ /// Convenience function for [`RelativeRemapping::new`]
54
+ pub fn into_relative ( self , root : impl AsRef < Path > ) -> RelativeRemapping {
55
+ RelativeRemapping :: new ( self , root)
56
+ }
57
+ }
58
+
52
59
#[ derive( thiserror:: Error , Debug , PartialEq , PartialOrd ) ]
53
60
pub enum RemappingError {
54
61
#[ error( "no prefix found" ) ]
@@ -222,6 +229,12 @@ impl RelativeRemapping {
222
229
self . path . parent = Some ( root) ;
223
230
self . into ( )
224
231
}
232
+
233
+ /// Converts this relative remapping into [`Remapping`] without the root path
234
+ pub fn to_relative_remapping ( mut self ) -> Remapping {
235
+ self . path . parent . take ( ) ;
236
+ self . into ( )
237
+ }
225
238
}
226
239
227
240
// Remappings are printed as `prefix=target`
@@ -263,8 +276,8 @@ impl From<Remapping> for RelativeRemapping {
263
276
/// resolve as a `weird-erc20/=/var/lib/weird-erc20/src/` remapping.
264
277
#[ derive( Clone , Debug , PartialEq , PartialOrd , Eq , Ord ) ]
265
278
pub struct RelativeRemappingPathBuf {
266
- parent : Option < PathBuf > ,
267
- path : PathBuf ,
279
+ pub parent : Option < PathBuf > ,
280
+ pub path : PathBuf ,
268
281
}
269
282
270
283
impl RelativeRemappingPathBuf {
@@ -647,6 +660,9 @@ mod tests {
647
660
assert_eq ! ( relative. path. relative( ) , Path :: new( & remapping. path) ) ;
648
661
assert_eq ! ( relative. path. original( ) , Path :: new( & remapping. path) ) ;
649
662
assert ! ( relative. path. parent. is_none( ) ) ;
663
+
664
+ let relative = RelativeRemapping :: new ( remapping. clone ( ) , "/a/b" ) ;
665
+ assert_eq ! ( relative. to_relative_remapping( ) , Remapping :: from_str( "oz/=c/d/" ) . unwrap( ) ) ;
650
666
}
651
667
652
668
#[ test]
0 commit comments