@@ -10,39 +10,39 @@ use crate::core::{GitReference, SourceKind};
10
10
/// The `Cargo.lock` structure.
11
11
#[ derive( Serialize , Deserialize , Debug ) ]
12
12
#[ cfg_attr( feature = "unstable-schema" , derive( schemars:: JsonSchema ) ) ]
13
- pub struct EncodableResolve {
13
+ pub struct TomlLockfile {
14
14
pub version : Option < u32 > ,
15
- pub package : Option < Vec < EncodableDependency > > ,
15
+ pub package : Option < Vec < TomlLockfileDependency > > ,
16
16
/// `root` is optional to allow backward compatibility.
17
- pub root : Option < EncodableDependency > ,
18
- pub metadata : Option < Metadata > ,
19
- #[ serde( default , skip_serializing_if = "Patch ::is_empty" ) ]
20
- pub patch : Patch ,
17
+ pub root : Option < TomlLockfileDependency > ,
18
+ pub metadata : Option < TomlLockfileMetadata > ,
19
+ #[ serde( default , skip_serializing_if = "TomlLockfilePatch ::is_empty" ) ]
20
+ pub patch : TomlLockfilePatch ,
21
21
}
22
22
23
23
#[ derive( Serialize , Deserialize , Debug , Default ) ]
24
24
#[ cfg_attr( feature = "unstable-schema" , derive( schemars:: JsonSchema ) ) ]
25
- pub struct Patch {
26
- pub unused : Vec < EncodableDependency > ,
25
+ pub struct TomlLockfilePatch {
26
+ pub unused : Vec < TomlLockfileDependency > ,
27
27
}
28
28
29
- pub type Metadata = BTreeMap < String , String > ;
29
+ pub type TomlLockfileMetadata = BTreeMap < String , String > ;
30
30
31
- impl Patch {
31
+ impl TomlLockfilePatch {
32
32
fn is_empty ( & self ) -> bool {
33
33
self . unused . is_empty ( )
34
34
}
35
35
}
36
36
37
37
#[ derive( Serialize , Deserialize , Debug , PartialOrd , Ord , PartialEq , Eq ) ]
38
38
#[ cfg_attr( feature = "unstable-schema" , derive( schemars:: JsonSchema ) ) ]
39
- pub struct EncodableDependency {
39
+ pub struct TomlLockfileDependency {
40
40
pub name : String ,
41
41
pub version : String ,
42
- pub source : Option < EncodableSourceId > ,
42
+ pub source : Option < TomlLockfileSourceId > ,
43
43
pub checksum : Option < String > ,
44
- pub dependencies : Option < Vec < EncodablePackageId > > ,
45
- pub replace : Option < EncodablePackageId > ,
44
+ pub dependencies : Option < Vec < TomlLockfilePackageId > > ,
45
+ pub replace : Option < TomlLockfilePackageId > ,
46
46
}
47
47
48
48
#[ derive( Debug , Clone ) ]
@@ -51,7 +51,7 @@ pub struct EncodableDependency {
51
51
derive( schemars:: JsonSchema ) ,
52
52
schemars( with = "String" )
53
53
) ]
54
- pub struct EncodableSourceId {
54
+ pub struct TomlLockfileSourceId {
55
55
/// Full string of the source
56
56
source_str : String ,
57
57
/// Used for sources ordering
@@ -60,7 +60,7 @@ pub struct EncodableSourceId {
60
60
url : Url ,
61
61
}
62
62
63
- impl EncodableSourceId {
63
+ impl TomlLockfileSourceId {
64
64
pub fn new ( source : String ) -> Result < Self , EncodableSourceIdError > {
65
65
let source_str = source. clone ( ) ;
66
66
let ( kind, url) = source. split_once ( '+' ) . ok_or_else ( || {
@@ -109,7 +109,7 @@ impl EncodableSourceId {
109
109
}
110
110
}
111
111
112
- impl ser:: Serialize for EncodableSourceId {
112
+ impl ser:: Serialize for TomlLockfileSourceId {
113
113
fn serialize < S > ( & self , s : S ) -> Result < S :: Ok , S :: Error >
114
114
where
115
115
S : ser:: Serializer ,
@@ -118,39 +118,39 @@ impl ser::Serialize for EncodableSourceId {
118
118
}
119
119
}
120
120
121
- impl < ' de > de:: Deserialize < ' de > for EncodableSourceId {
121
+ impl < ' de > de:: Deserialize < ' de > for TomlLockfileSourceId {
122
122
fn deserialize < D > ( d : D ) -> Result < Self , D :: Error >
123
123
where
124
124
D : de:: Deserializer < ' de > ,
125
125
{
126
126
let s = String :: deserialize ( d) ?;
127
- Ok ( EncodableSourceId :: new ( s) . map_err ( de:: Error :: custom) ?)
127
+ Ok ( TomlLockfileSourceId :: new ( s) . map_err ( de:: Error :: custom) ?)
128
128
}
129
129
}
130
130
131
- impl std:: hash:: Hash for EncodableSourceId {
131
+ impl std:: hash:: Hash for TomlLockfileSourceId {
132
132
fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
133
133
self . kind . hash ( state) ;
134
134
self . url . hash ( state) ;
135
135
}
136
136
}
137
137
138
- impl std:: cmp:: PartialEq for EncodableSourceId {
138
+ impl std:: cmp:: PartialEq for TomlLockfileSourceId {
139
139
fn eq ( & self , other : & Self ) -> bool {
140
140
self . kind == other. kind && self . url == other. url
141
141
}
142
142
}
143
143
144
- impl std:: cmp:: Eq for EncodableSourceId { }
144
+ impl std:: cmp:: Eq for TomlLockfileSourceId { }
145
145
146
- impl PartialOrd for EncodableSourceId {
147
- fn partial_cmp ( & self , other : & EncodableSourceId ) -> Option < Ordering > {
146
+ impl PartialOrd for TomlLockfileSourceId {
147
+ fn partial_cmp ( & self , other : & TomlLockfileSourceId ) -> Option < Ordering > {
148
148
Some ( self . cmp ( other) )
149
149
}
150
150
}
151
151
152
- impl Ord for EncodableSourceId {
153
- fn cmp ( & self , other : & EncodableSourceId ) -> Ordering {
152
+ impl Ord for TomlLockfileSourceId {
153
+ fn cmp ( & self , other : & TomlLockfileSourceId ) -> Ordering {
154
154
self . kind
155
155
. cmp ( & other. kind )
156
156
. then_with ( || self . url . cmp ( & other. url ) )
@@ -159,13 +159,13 @@ impl Ord for EncodableSourceId {
159
159
160
160
#[ derive( Debug , PartialOrd , Ord , PartialEq , Eq , Hash , Clone ) ]
161
161
#[ cfg_attr( feature = "unstable-schema" , derive( schemars:: JsonSchema ) ) ]
162
- pub struct EncodablePackageId {
162
+ pub struct TomlLockfilePackageId {
163
163
pub name : String ,
164
164
pub version : Option < String > ,
165
- pub source : Option < EncodableSourceId > ,
165
+ pub source : Option < TomlLockfileSourceId > ,
166
166
}
167
167
168
- impl fmt:: Display for EncodablePackageId {
168
+ impl fmt:: Display for TomlLockfilePackageId {
169
169
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
170
170
write ! ( f, "{}" , self . name) ?;
171
171
if let Some ( s) = & self . version {
@@ -178,33 +178,33 @@ impl fmt::Display for EncodablePackageId {
178
178
}
179
179
}
180
180
181
- impl FromStr for EncodablePackageId {
181
+ impl FromStr for TomlLockfilePackageId {
182
182
type Err = EncodablePackageIdError ;
183
183
184
- fn from_str ( s : & str ) -> Result < EncodablePackageId , Self :: Err > {
184
+ fn from_str ( s : & str ) -> Result < TomlLockfilePackageId , Self :: Err > {
185
185
let mut s = s. splitn ( 3 , ' ' ) ;
186
186
let name = s. next ( ) . unwrap ( ) ;
187
187
let version = s. next ( ) ;
188
188
let source_id = match s. next ( ) {
189
189
Some ( s) => {
190
190
if let Some ( s) = s. strip_prefix ( '(' ) . and_then ( |s| s. strip_suffix ( ')' ) ) {
191
- Some ( EncodableSourceId :: new ( s. to_string ( ) ) ?)
191
+ Some ( TomlLockfileSourceId :: new ( s. to_string ( ) ) ?)
192
192
} else {
193
193
return Err ( EncodablePackageIdErrorKind :: InvalidSerializedPackageId . into ( ) ) ;
194
194
}
195
195
}
196
196
None => None ,
197
197
} ;
198
198
199
- Ok ( EncodablePackageId {
199
+ Ok ( TomlLockfilePackageId {
200
200
name : name. to_string ( ) ,
201
201
version : version. map ( |v| v. to_string ( ) ) ,
202
202
source : source_id,
203
203
} )
204
204
}
205
205
}
206
206
207
- impl ser:: Serialize for EncodablePackageId {
207
+ impl ser:: Serialize for TomlLockfilePackageId {
208
208
fn serialize < S > ( & self , s : S ) -> Result < S :: Ok , S :: Error >
209
209
where
210
210
S : ser:: Serializer ,
@@ -213,14 +213,14 @@ impl ser::Serialize for EncodablePackageId {
213
213
}
214
214
}
215
215
216
- impl < ' de > de:: Deserialize < ' de > for EncodablePackageId {
217
- fn deserialize < D > ( d : D ) -> Result < EncodablePackageId , D :: Error >
216
+ impl < ' de > de:: Deserialize < ' de > for TomlLockfilePackageId {
217
+ fn deserialize < D > ( d : D ) -> Result < TomlLockfilePackageId , D :: Error >
218
218
where
219
219
D : de:: Deserializer < ' de > ,
220
220
{
221
221
String :: deserialize ( d) . and_then ( |string| {
222
222
string
223
- . parse :: < EncodablePackageId > ( )
223
+ . parse :: < TomlLockfilePackageId > ( )
224
224
. map_err ( de:: Error :: custom)
225
225
} )
226
226
}
@@ -266,7 +266,7 @@ enum EncodablePackageIdErrorKind {
266
266
#[ cfg( feature = "unstable-schema" ) ]
267
267
#[ test]
268
268
fn dump_lockfile_schema ( ) {
269
- let schema = schemars:: schema_for!( crate :: lockfile:: EncodableResolve ) ;
269
+ let schema = schemars:: schema_for!( crate :: lockfile:: TomlLockfile ) ;
270
270
let dump = serde_json:: to_string_pretty ( & schema) . unwrap ( ) ;
271
271
snapbox:: assert_data_eq!( dump, snapbox:: file!( "../lockfile.schema.json" ) . raw( ) ) ;
272
272
}
0 commit comments