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