Skip to content

Commit

Permalink
Change the type of size to be u64
Browse files Browse the repository at this point in the history
Sizes cannot be negative.

This is a semver break; and yes the type inference fallout
is a minor annoyance, but this is a notable improvement
for code which is accepting `Descriptor` objects and
interacting with other things on the filesystem that operate
in terms of `u64` typically.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Aug 27, 2024
1 parent 9e9d3fc commit ad7b406
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ use oci_spec::image::{

let config = DescriptorBuilder::default()
.media_type(MediaType::ImageConfig)
.size(7023)
.size(7023u64)
.digest("sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7")
.build()
.expect("build config descriptor");

let layers: Vec<Descriptor> = [
(
32654,
32654u64,
"sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0",
),
(
Expand Down
4 changes: 2 additions & 2 deletions src/image/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ mod tests {
fn create_manifest() -> ArtifactManifest {
let blob = DescriptorBuilder::default()
.media_type(MediaType::Other("application/gzip".to_string()))
.size(123)
.size(123u64)
.digest(
"sha256:87923725d74f4bfb94c9e86d64170f7521aad8221a5de834851470ca142da630"
.to_string(),
Expand All @@ -235,7 +235,7 @@ mod tests {
.unwrap();
let subject = DescriptorBuilder::default()
.media_type(MediaType::ImageManifest)
.size(1234)
.size(1234u64)
.digest(
"sha256:cc06a2839488b8bd2a2b99dcdc03d5cfd818eed72ad08ef3cc197aac64c0d0a0"
.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/image/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Descriptor {
/// length of the retrieved content does not match the specified
/// length, the content SHOULD NOT be trusted.
#[getset(get_copy = "pub", set = "pub")]
size: i64,
size: u64,
/// This OPTIONAL property specifies a list of URIs from which this
/// object MAY be downloaded. Each entry MUST conform to [RFC 3986](https://tools.ietf.org/html/rfc3986).
/// Entries SHOULD use the http and https schemes, as defined
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct Platform {

impl Descriptor {
/// Construct a new descriptor with the required fields.
pub fn new(media_type: MediaType, size: i64, digest: impl Into<String>) -> Self {
pub fn new(media_type: MediaType, size: u64, digest: impl Into<String>) -> Self {
Self {
media_type,
size,
Expand Down
4 changes: 2 additions & 2 deletions src/image/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
let ppc_manifest = DescriptorBuilder::default()
.media_type(MediaType::ImageManifest)
.digest("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f")
.size(7143)
.size(7143u64)
.platform(
PlatformBuilder::default()
.architecture(Arch::PowerPC64le)
Expand All @@ -253,7 +253,7 @@ mod tests {
let amd64_manifest = DescriptorBuilder::default()
.media_type(MediaType::ImageManifest)
.digest("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270")
.size(7682)
.size(7682u64)
.platform(
PlatformBuilder::default()
.architecture(Arch::Amd64)
Expand Down
4 changes: 2 additions & 2 deletions src/image/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ mod tests {

let config = DescriptorBuilder::default()
.media_type(MediaType::ImageConfig)
.size(7023)
.size(7023u64)
.digest("sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7")
.build()
.expect("build config descriptor");

let layers: Vec<Descriptor> = [
(
32654,
32654u64,
"sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0",
),
(
Expand Down

0 comments on commit ad7b406

Please sign in to comment.