pub fn normalize_image_ref(image: &str) -> StringExpand description
Canonicalize an OCI image reference.
All equivalent spellings of the same image produce an identical string, which is safe to use as a cache key or protocol field.
§Normalization rules (applied in order)
index.docker.iois rewritten todocker.io(legacy alias).- A missing registry defaults to
docker.io. - Single-component names on
docker.ioreceive thelibrary/prefix (e.g.alpine→docker.io/library/alpine). - A missing tag defaults to
:latest. When a digest (@sha256:…) is present it takes precedence and any tag is dropped.
§Examples
use smolvm_protocol::normalize_image_ref;
assert_eq!(normalize_image_ref("alpine"),
"docker.io/library/alpine:latest");
assert_eq!(normalize_image_ref("alpine:3.20"),
"docker.io/library/alpine:3.20");
assert_eq!(normalize_image_ref("docker.io/alpine:3.20"),
"docker.io/library/alpine:3.20");
assert_eq!(normalize_image_ref("docker.io/library/alpine:3.20"),
"docker.io/library/alpine:3.20");
assert_eq!(normalize_image_ref("ghcr.io/owner/repo:v1"),
"ghcr.io/owner/repo:v1");