pub struct ImageReference {
pub transport: Transport,
pub name: String,
}Expand description
Combination of a transport and image name.
For example, docker://quay.io/exampleos/blah:latest would be parsed as:
- transport:
Registry - name:
quay.io/exampleos/blah:latest
§Name formats by transport
The name field format varies by transport:
| Transport | Name format | Example |
|---|---|---|
Registry | [domain/]name[:tag][@digest] | quay.io/example/image:latest |
OciDir | path[:reference] | /path/to/oci-layout:mytag |
OciArchive | path[:reference] | /path/to/image.tar:v1.0 |
DockerArchive | path[:docker-reference] | /path/to/image.tar:myimage:tag |
ContainerStorage | [[storage-spec]]{image-id|docker-ref} | localhost/myimage:latest |
Dir | path | /path/to/directory |
DockerDaemon | docker-reference or algo:digest | myimage:latest |
Fields§
§transport: TransportThe storage and transport for the image
name: StringThe image name - format depends on transport (see struct docs)
Implementations§
Source§impl ImageReference
impl ImageReference
Sourcepub fn new(transport: Transport, name: impl Into<String>) -> Self
pub fn new(transport: Transport, name: impl Into<String>) -> Self
Create a new image reference from a transport and name.
§Examples
use containers_image_proxy::{ImageReference, Transport};
let imgref = ImageReference::new(Transport::Registry, "quay.io/example/image:tag");
assert_eq!(imgref.to_string(), "docker://quay.io/example/image:tag");Sourcepub fn new_registry(reference: Reference) -> Self
pub fn new_registry(reference: Reference) -> Self
Create a new registry image reference from a parsed OCI Reference.
§Examples
use containers_image_proxy::ImageReference;
use oci_spec::distribution::Reference;
let oci_ref: Reference = "quay.io/example/image:latest".parse().unwrap();
let imgref = ImageReference::new_registry(oci_ref);
assert_eq!(imgref.to_string(), "docker://quay.io/example/image:latest");Sourcepub fn try_new_registry(name: &str) -> Result<Self, ParseError>
pub fn try_new_registry(name: &str) -> Result<Self, ParseError>
Try to create a new registry image reference by parsing the name.
Returns an error if the name is not a valid OCI distribution reference.
§Examples
use containers_image_proxy::ImageReference;
let imgref = ImageReference::try_new_registry("quay.io/example/image:latest").unwrap();
assert_eq!(imgref.to_string(), "docker://quay.io/example/image:latest");
// Invalid references return an error
assert!(ImageReference::try_new_registry("not a valid reference!").is_err());Sourcepub fn as_registry(&self) -> Option<Result<Reference, ParseError>>
pub fn as_registry(&self) -> Option<Result<Reference, ParseError>>
For Registry transport, parse the name as an OCI distribution Reference.
Returns None for non-Registry transports. For Registry transport,
returns Some(Result) with the parsed reference or a parse error.
This is useful when you need structured access to the registry, repository, tag, and digest components of a registry image reference.
§Examples
use containers_image_proxy::{ImageReference, Transport};
let imgref: ImageReference = "docker://quay.io/example/image:latest".try_into().unwrap();
let oci_ref = imgref.as_registry().unwrap().unwrap();
assert_eq!(oci_ref.registry(), "quay.io");
assert_eq!(oci_ref.repository(), "example/image");
assert_eq!(oci_ref.tag(), Some("latest"));
// Non-registry transports return None
let imgref: ImageReference = "oci:/path/to/image".try_into().unwrap();
assert!(imgref.as_registry().is_none());Sourcepub fn as_containers_storage(&self) -> Option<ContainersStorageRef<'_>>
pub fn as_containers_storage(&self) -> Option<ContainersStorageRef<'_>>
For ContainerStorage transport, parse into structured components.
Returns None for non-ContainerStorage transports.
§Examples
use containers_image_proxy::{ImageReference, Transport};
// Simple image reference
let imgref: ImageReference = "containers-storage:localhost/myimage:tag".try_into().unwrap();
let csref = imgref.as_containers_storage().unwrap();
assert_eq!(csref.store_spec(), None);
assert_eq!(csref.image(), "localhost/myimage:tag");
// With store specifier
let imgref: ImageReference = "containers-storage:[overlay@/var/lib/containers]busybox".try_into().unwrap();
let csref = imgref.as_containers_storage().unwrap();
assert_eq!(csref.store_spec(), Some("overlay@/var/lib/containers"));
assert_eq!(csref.image(), "busybox");
// Normalizing sha256: prefix (workaround for skopeo#2750)
let imgref: ImageReference = "containers-storage:sha256:abc123".try_into().unwrap();
let csref = imgref.as_containers_storage().unwrap();
assert_eq!(csref.image_for_skopeo(), "abc123");Trait Implementations§
Source§impl Clone for ImageReference
impl Clone for ImageReference
Source§fn clone(&self) -> ImageReference
fn clone(&self) -> ImageReference
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageReference
impl Debug for ImageReference
Source§impl Display for ImageReference
impl Display for ImageReference
Source§impl FromStr for ImageReference
impl FromStr for ImageReference
Source§impl Hash for ImageReference
impl Hash for ImageReference
Source§impl PartialEq for ImageReference
impl PartialEq for ImageReference
Source§impl TryFrom<&str> for ImageReference
impl TryFrom<&str> for ImageReference
Source§fn try_from(value: &str) -> Result<Self, ImageReferenceError>
fn try_from(value: &str) -> Result<Self, ImageReferenceError>
Parse an image reference string into transport and name components.
§Examples
use containers_image_proxy::transport::{ImageReference, Transport};
let imgref: ImageReference = "docker://quay.io/example/image:tag".try_into().unwrap();
assert_eq!(imgref.transport, Transport::Registry);
assert_eq!(imgref.name, "quay.io/example/image:tag");
let imgref: ImageReference = "containers-storage:localhost/myimage".try_into().unwrap();
assert_eq!(imgref.transport, Transport::ContainerStorage);
assert_eq!(imgref.name, "localhost/myimage");Source§type Error = ImageReferenceError
type Error = ImageReferenceError
impl Eq for ImageReference
impl StructuralPartialEq for ImageReference
Auto Trait Implementations§
impl Freeze for ImageReference
impl RefUnwindSafe for ImageReference
impl Send for ImageReference
impl Sync for ImageReference
impl Unpin for ImageReference
impl UnwindSafe for ImageReference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more