Skip to content

Commit ab8c655

Browse files
committed
feat: Add support for 'rust_version'
This was added to the index in rust-lang/crates.io#6267. crates.io is automatically injecting it into the index, even without using the nightly cargo that supports it. My plan is to use this to make cargo-upgrade more MSRV aware (in version reqs despite the resolver not yet being MSRV aware).
1 parent 4ab6b51 commit ab8c655

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ pub struct Version {
9090
features2: Option<Box<HashMap<String, Vec<String>>>>,
9191
#[serde(skip_serializing_if = "Option::is_none")]
9292
links: Option<Box<SmolStr>>,
93+
#[serde(default)]
94+
rust_version: Option<SmolStr>,
9395
#[serde(with = "hex")]
9496
cksum: [u8; 32],
9597
#[serde(default)]
@@ -155,6 +157,18 @@ impl Version {
155157
self.yanked
156158
}
157159

160+
/// Required version of rust
161+
///
162+
/// Corresponds to `package.rust-version`.
163+
///
164+
/// Added in 2023 (see <https://github.com/rust-lang/crates.io/pull/6267>),
165+
/// can be `None` if published before then or if not set in the manifest.
166+
#[inline]
167+
#[must_use]
168+
pub fn rust_version(&self) -> Option<&str> {
169+
self.rust_version.as_deref()
170+
}
171+
158172
/// Where to find crate tarball
159173
#[must_use]
160174
pub fn download_url(&self, index: &IndexConfig) -> Option<String> {
@@ -652,7 +666,7 @@ mod test {
652666

653667
#[test]
654668
fn sizes() {
655-
assert!(std::mem::size_of::<Version>() <= 128);
669+
assert!(std::mem::size_of::<Version>() <= 152);
656670
assert!(std::mem::size_of::<Crate>() <= 16);
657671
assert!(std::mem::size_of::<Dependency>() <= 80);
658672
}
@@ -752,4 +766,10 @@ mod test {
752766
assert_eq!(["x"], &f2["b"][..]);
753767
assert_eq!(["y"], &f2["c"][..]);
754768
}
769+
770+
#[test]
771+
fn rust_version() {
772+
let c = Crate::from_slice(br#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{},"features2":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "rust_version":"1.64.0"}"#).unwrap();
773+
assert_eq!(c.most_recent_version().rust_version(), Some("1.64.0"));
774+
}
755775
}

0 commit comments

Comments
 (0)