Skip to content

Commit 703988f

Browse files
committed
refactor: rename lockfile schemas scheme
Manifests schemas use `TomlManifest`. To match, we rename the lockfile schemas to `TomlLockfile`
1 parent d51d7f6 commit 703988f

File tree

5 files changed

+73
-72
lines changed

5 files changed

+73
-72
lines changed

crates/cargo-util-schemas/lockfile.schema.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"title": "EncodableResolve",
3+
"title": "TomlLockfile",
44
"description": "The `Cargo.lock` structure.",
55
"type": "object",
66
"properties": {
@@ -18,14 +18,14 @@
1818
"null"
1919
],
2020
"items": {
21-
"$ref": "#/$defs/EncodableDependency"
21+
"$ref": "#/$defs/TomlLockfileDependency"
2222
}
2323
},
2424
"root": {
2525
"description": "`root` is optional to allow backward compatibility.",
2626
"anyOf": [
2727
{
28-
"$ref": "#/$defs/EncodableDependency"
28+
"$ref": "#/$defs/TomlLockfileDependency"
2929
},
3030
{
3131
"type": "null"
@@ -42,11 +42,11 @@
4242
}
4343
},
4444
"patch": {
45-
"$ref": "#/$defs/Patch"
45+
"$ref": "#/$defs/TomlLockfilePatch"
4646
}
4747
},
4848
"$defs": {
49-
"EncodableDependency": {
49+
"TomlLockfileDependency": {
5050
"type": "object",
5151
"properties": {
5252
"name": {
@@ -73,13 +73,13 @@
7373
"null"
7474
],
7575
"items": {
76-
"$ref": "#/$defs/EncodablePackageId"
76+
"$ref": "#/$defs/TomlLockfilePackageId"
7777
}
7878
},
7979
"replace": {
8080
"anyOf": [
8181
{
82-
"$ref": "#/$defs/EncodablePackageId"
82+
"$ref": "#/$defs/TomlLockfilePackageId"
8383
},
8484
{
8585
"type": "null"
@@ -92,7 +92,7 @@
9292
"version"
9393
]
9494
},
95-
"EncodablePackageId": {
95+
"TomlLockfilePackageId": {
9696
"type": "object",
9797
"properties": {
9898
"name": {
@@ -115,13 +115,13 @@
115115
"name"
116116
]
117117
},
118-
"Patch": {
118+
"TomlLockfilePatch": {
119119
"type": "object",
120120
"properties": {
121121
"unused": {
122122
"type": "array",
123123
"items": {
124-
"$ref": "#/$defs/EncodableDependency"
124+
"$ref": "#/$defs/TomlLockfileDependency"
125125
}
126126
}
127127
},

crates/cargo-util-schemas/src/lockfile.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ use crate::core::{GitReference, SourceKind};
1010
/// The `Cargo.lock` structure.
1111
#[derive(Serialize, Deserialize, Debug)]
1212
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
13-
pub struct EncodableResolve {
13+
pub struct TomlLockfile {
1414
pub version: Option<u32>,
15-
pub package: Option<Vec<EncodableDependency>>,
15+
pub package: Option<Vec<TomlLockfileDependency>>,
1616
/// `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,
2121
}
2222

2323
#[derive(Serialize, Deserialize, Debug, Default)]
2424
#[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>,
2727
}
2828

29-
pub type Metadata = BTreeMap<String, String>;
29+
pub type TomlLockfileMetadata = BTreeMap<String, String>;
3030

31-
impl Patch {
31+
impl TomlLockfilePatch {
3232
fn is_empty(&self) -> bool {
3333
self.unused.is_empty()
3434
}
3535
}
3636

3737
#[derive(Serialize, Deserialize, Debug, PartialOrd, Ord, PartialEq, Eq)]
3838
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
39-
pub struct EncodableDependency {
39+
pub struct TomlLockfileDependency {
4040
pub name: String,
4141
pub version: String,
42-
pub source: Option<EncodableSourceId>,
42+
pub source: Option<TomlLockfileSourceId>,
4343
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>,
4646
}
4747

4848
#[derive(Debug, Clone)]
@@ -51,7 +51,7 @@ pub struct EncodableDependency {
5151
derive(schemars::JsonSchema),
5252
schemars(with = "String")
5353
)]
54-
pub struct EncodableSourceId {
54+
pub struct TomlLockfileSourceId {
5555
/// Full string of the source
5656
source_str: String,
5757
/// Used for sources ordering
@@ -60,7 +60,7 @@ pub struct EncodableSourceId {
6060
url: Url,
6161
}
6262

63-
impl EncodableSourceId {
63+
impl TomlLockfileSourceId {
6464
pub fn new(source: String) -> Result<Self, EncodableSourceIdError> {
6565
let source_str = source.clone();
6666
let (kind, url) = source.split_once('+').ok_or_else(|| {
@@ -109,7 +109,7 @@ impl EncodableSourceId {
109109
}
110110
}
111111

112-
impl ser::Serialize for EncodableSourceId {
112+
impl ser::Serialize for TomlLockfileSourceId {
113113
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
114114
where
115115
S: ser::Serializer,
@@ -118,39 +118,39 @@ impl ser::Serialize for EncodableSourceId {
118118
}
119119
}
120120

121-
impl<'de> de::Deserialize<'de> for EncodableSourceId {
121+
impl<'de> de::Deserialize<'de> for TomlLockfileSourceId {
122122
fn deserialize<D>(d: D) -> Result<Self, D::Error>
123123
where
124124
D: de::Deserializer<'de>,
125125
{
126126
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)?)
128128
}
129129
}
130130

131-
impl std::hash::Hash for EncodableSourceId {
131+
impl std::hash::Hash for TomlLockfileSourceId {
132132
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
133133
self.kind.hash(state);
134134
self.url.hash(state);
135135
}
136136
}
137137

138-
impl std::cmp::PartialEq for EncodableSourceId {
138+
impl std::cmp::PartialEq for TomlLockfileSourceId {
139139
fn eq(&self, other: &Self) -> bool {
140140
self.kind == other.kind && self.url == other.url
141141
}
142142
}
143143

144-
impl std::cmp::Eq for EncodableSourceId {}
144+
impl std::cmp::Eq for TomlLockfileSourceId {}
145145

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> {
148148
Some(self.cmp(other))
149149
}
150150
}
151151

152-
impl Ord for EncodableSourceId {
153-
fn cmp(&self, other: &EncodableSourceId) -> Ordering {
152+
impl Ord for TomlLockfileSourceId {
153+
fn cmp(&self, other: &TomlLockfileSourceId) -> Ordering {
154154
self.kind
155155
.cmp(&other.kind)
156156
.then_with(|| self.url.cmp(&other.url))
@@ -159,13 +159,13 @@ impl Ord for EncodableSourceId {
159159

160160
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Hash, Clone)]
161161
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
162-
pub struct EncodablePackageId {
162+
pub struct TomlLockfilePackageId {
163163
pub name: String,
164164
pub version: Option<String>,
165-
pub source: Option<EncodableSourceId>,
165+
pub source: Option<TomlLockfileSourceId>,
166166
}
167167

168-
impl fmt::Display for EncodablePackageId {
168+
impl fmt::Display for TomlLockfilePackageId {
169169
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
170170
write!(f, "{}", self.name)?;
171171
if let Some(s) = &self.version {
@@ -178,33 +178,33 @@ impl fmt::Display for EncodablePackageId {
178178
}
179179
}
180180

181-
impl FromStr for EncodablePackageId {
181+
impl FromStr for TomlLockfilePackageId {
182182
type Err = EncodablePackageIdError;
183183

184-
fn from_str(s: &str) -> Result<EncodablePackageId, Self::Err> {
184+
fn from_str(s: &str) -> Result<TomlLockfilePackageId, Self::Err> {
185185
let mut s = s.splitn(3, ' ');
186186
let name = s.next().unwrap();
187187
let version = s.next();
188188
let source_id = match s.next() {
189189
Some(s) => {
190190
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())?)
192192
} else {
193193
return Err(EncodablePackageIdErrorKind::InvalidSerializedPackageId.into());
194194
}
195195
}
196196
None => None,
197197
};
198198

199-
Ok(EncodablePackageId {
199+
Ok(TomlLockfilePackageId {
200200
name: name.to_string(),
201201
version: version.map(|v| v.to_string()),
202202
source: source_id,
203203
})
204204
}
205205
}
206206

207-
impl ser::Serialize for EncodablePackageId {
207+
impl ser::Serialize for TomlLockfilePackageId {
208208
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
209209
where
210210
S: ser::Serializer,
@@ -213,14 +213,14 @@ impl ser::Serialize for EncodablePackageId {
213213
}
214214
}
215215

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>
218218
where
219219
D: de::Deserializer<'de>,
220220
{
221221
String::deserialize(d).and_then(|string| {
222222
string
223-
.parse::<EncodablePackageId>()
223+
.parse::<TomlLockfilePackageId>()
224224
.map_err(de::Error::custom)
225225
})
226226
}
@@ -266,7 +266,7 @@ enum EncodablePackageIdErrorKind {
266266
#[cfg(feature = "unstable-schema")]
267267
#[test]
268268
fn dump_lockfile_schema() {
269-
let schema = schemars::schema_for!(crate::lockfile::EncodableResolve);
269+
let schema = schemars::schema_for!(crate::lockfile::TomlLockfile);
270270
let dump = serde_json::to_string_pretty(&schema).unwrap();
271271
snapbox::assert_data_eq!(dump, snapbox::file!("../lockfile.schema.json").raw());
272272
}

0 commit comments

Comments
 (0)