@@ -103,16 +103,18 @@ pub struct TomlLockfileSourceId {
103
103
}
104
104
105
105
impl TomlLockfileSourceId {
106
- pub fn new ( source : String ) -> Result < Self , EncodableSourceIdError > {
106
+ pub fn new ( source : String ) -> Result < Self , TomlLockfileSourceIdError > {
107
107
let source_str = source. clone ( ) ;
108
108
let ( kind, url) = source. split_once ( '+' ) . ok_or_else ( || {
109
- EncodableSourceIdError ( EncodableSourceIdErrorKind :: InvalidSource ( source. clone ( ) ) . into ( ) )
109
+ TomlLockfileSourceIdError (
110
+ TomlLockfileSourceIdErrorKind :: InvalidSource ( source. clone ( ) ) . into ( ) ,
111
+ )
110
112
} ) ?;
111
113
112
114
// Sparse URLs store the kind prefix (sparse+) in the URL. Therefore, for sparse kinds, we
113
115
// want to use the raw `source` instead of the splitted `url`.
114
116
let url = Url :: parse ( if kind == "sparse" { & source } else { url } ) . map_err ( |msg| {
115
- EncodableSourceIdErrorKind :: InvalidUrl {
117
+ TomlLockfileSourceIdErrorKind :: InvalidUrl {
116
118
url : url. to_string ( ) ,
117
119
msg : msg. to_string ( ) ,
118
120
}
@@ -127,7 +129,9 @@ impl TomlLockfileSourceId {
127
129
"sparse" => SourceKind :: SparseRegistry ,
128
130
"path" => SourceKind :: Path ,
129
131
kind => {
130
- return Err ( EncodableSourceIdErrorKind :: UnsupportedSource ( kind. to_string ( ) ) . into ( ) ) ;
132
+ return Err (
133
+ TomlLockfileSourceIdErrorKind :: UnsupportedSource ( kind. to_string ( ) ) . into ( ) ,
134
+ ) ;
131
135
}
132
136
} ;
133
137
@@ -230,7 +234,7 @@ impl fmt::Display for TomlLockfilePackageId {
230
234
}
231
235
232
236
impl FromStr for TomlLockfilePackageId {
233
- type Err = EncodablePackageIdError ;
237
+ type Err = TomlLockfilePackageIdError ;
234
238
235
239
fn from_str ( s : & str ) -> Result < TomlLockfilePackageId , Self :: Err > {
236
240
let mut s = s. splitn ( 3 , ' ' ) ;
@@ -241,7 +245,7 @@ impl FromStr for TomlLockfilePackageId {
241
245
if let Some ( s) = s. strip_prefix ( '(' ) . and_then ( |s| s. strip_suffix ( ')' ) ) {
242
246
Some ( TomlLockfileSourceId :: new ( s. to_string ( ) ) ?)
243
247
} else {
244
- return Err ( EncodablePackageIdErrorKind :: InvalidSerializedPackageId . into ( ) ) ;
248
+ return Err ( TomlLockfilePackageIdErrorKind :: InvalidSerializedPackageId . into ( ) ) ;
245
249
}
246
250
}
247
251
None => None ,
@@ -279,11 +283,11 @@ impl<'de> de::Deserialize<'de> for TomlLockfilePackageId {
279
283
280
284
#[ derive( Debug , thiserror:: Error ) ]
281
285
#[ error( transparent) ]
282
- pub struct EncodableSourceIdError ( #[ from] EncodableSourceIdErrorKind ) ;
286
+ pub struct TomlLockfileSourceIdError ( #[ from] TomlLockfileSourceIdErrorKind ) ;
283
287
284
288
#[ non_exhaustive]
285
289
#[ derive( Debug , thiserror:: Error ) ]
286
- enum EncodableSourceIdErrorKind {
290
+ enum TomlLockfileSourceIdErrorKind {
287
291
#[ error( "invalid source `{0}`" ) ]
288
292
InvalidSource ( String ) ,
289
293
@@ -296,22 +300,22 @@ enum EncodableSourceIdErrorKind {
296
300
297
301
#[ derive( Debug , thiserror:: Error ) ]
298
302
#[ error( transparent) ]
299
- pub struct EncodablePackageIdError ( #[ from] EncodablePackageIdErrorKind ) ;
303
+ pub struct TomlLockfilePackageIdError ( #[ from] TomlLockfilePackageIdErrorKind ) ;
300
304
301
- impl From < EncodableSourceIdError > for EncodablePackageIdError {
302
- fn from ( value : EncodableSourceIdError ) -> Self {
303
- EncodablePackageIdErrorKind :: Source ( value) . into ( )
305
+ impl From < TomlLockfileSourceIdError > for TomlLockfilePackageIdError {
306
+ fn from ( value : TomlLockfileSourceIdError ) -> Self {
307
+ TomlLockfilePackageIdErrorKind :: Source ( value) . into ( )
304
308
}
305
309
}
306
310
307
311
#[ non_exhaustive]
308
312
#[ derive( Debug , thiserror:: Error ) ]
309
- enum EncodablePackageIdErrorKind {
313
+ enum TomlLockfilePackageIdErrorKind {
310
314
#[ error( "invalid serialied PackageId" ) ]
311
315
InvalidSerializedPackageId ,
312
316
313
317
#[ error( transparent) ]
314
- Source ( #[ from] EncodableSourceIdError ) ,
318
+ Source ( #[ from] TomlLockfileSourceIdError ) ,
315
319
}
316
320
317
321
#[ cfg( feature = "unstable-schema" ) ]
@@ -325,7 +329,7 @@ fn dump_lockfile_schema() {
325
329
#[ cfg( test) ]
326
330
mod tests {
327
331
use crate :: core:: { GitReference , SourceKind } ;
328
- use crate :: lockfile:: { EncodableSourceIdErrorKind , TomlLockfileSourceId } ;
332
+ use crate :: lockfile:: { TomlLockfileSourceId , TomlLockfileSourceIdErrorKind } ;
329
333
330
334
#[ track_caller]
331
335
fn ok ( source_str : & str , source_kind : SourceKind , url : & str ) {
@@ -389,15 +393,15 @@ mod tests {
389
393
fn bad_sources ( ) {
390
394
err ! (
391
395
"unknown+https://my-crates.io" ,
392
- EncodableSourceIdErrorKind :: UnsupportedSource ( ..)
396
+ TomlLockfileSourceIdErrorKind :: UnsupportedSource ( ..)
393
397
) ;
394
398
err ! (
395
399
"registry+https//github.com/rust-lang/crates.io-index" ,
396
- EncodableSourceIdErrorKind :: InvalidUrl { .. }
400
+ TomlLockfileSourceIdErrorKind :: InvalidUrl { .. }
397
401
) ;
398
402
err ! (
399
403
"https//github.com/rust-lang/crates.io-index" ,
400
- EncodableSourceIdErrorKind :: InvalidSource ( ..)
404
+ TomlLockfileSourceIdErrorKind :: InvalidSource ( ..)
401
405
) ;
402
406
}
403
407
}
0 commit comments