pub struct DockerImage {
pub registry: Option<String>,
pub name: String,
pub tag: Option<String>,
pub digest: Option<String>,
}
Expand description
Represents a parsed Docker image reference.
A Docker image can have the following components:
registry
: The optional registry URL (e.g.,docker.io
,ghcr.io
, or a custom registry likemy-registry.local:5000
).name
: The mandatory name of the image, which may include namespaces (e.g.,library/nginx
).tag
: An optional version tag for the image (e.g.,latest
,v1.0.0
).digest
: An optional digest for the image content (e.g.,sha256:<64-hex-digest>
).
§Examples
use docker_image::DockerImage;
let image = DockerImage::parse("docker.io/library/nginx:latest").unwrap();
assert_eq!(image.registry, Some("docker.io".to_string()));
assert_eq!(image.name, "library/nginx".to_string());
assert_eq!(image.tag, Some("latest".to_string()));
assert_eq!(image.digest, None);
Fields§
§registry: Option<String>
The optional registry URL.
name: String
The name of the image, including namespaces if present.
tag: Option<String>
The optional version tag.
digest: Option<String>
The optional content digest (e.g., sha256:<64-hex-digest>
).
Implementations§
Source§impl DockerImage
impl DockerImage
Sourcepub fn parse(image_str: &str) -> Result<Self, DockerImageError>
pub fn parse(image_str: &str) -> Result<Self, DockerImageError>
Parses a Docker image string into its structured components.
This is a convenience function for DockerImage::from_str
.
§Examples
use docker_image::DockerImage;
let image = DockerImage::parse("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2").unwrap();
assert_eq!(image.name, "ubuntu");
assert_eq!(image.digest, Some("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2".to_string()));
Trait Implementations§
Source§impl Debug for DockerImage
impl Debug for DockerImage
Source§impl Display for DockerImage
impl Display for DockerImage
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the DockerImage
as a valid Docker image reference string.
The format includes:
[registry/]name[:tag][@digest]
Examples:
nginx
nginx:latest
docker.io/library/nginx:latest
ubuntu@sha256:deadbeef1234567890abcdef1234567890abcdef1234567890abcdef1234
my-registry.local:5000/library/image-name:v1.0.0@sha256:deadbeef1234567890abcdef1234567890abcdef1234567890abcdef1234
Source§impl FromStr for DockerImage
impl FromStr for DockerImage
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses a Docker image string into its structured components.
This function supports the following Docker image formats:
nginx
nginx:latest
docker.io/library/nginx
docker.io/library/nginx:latest
docker.io/library/nginx@sha256:<digest>
docker.io/library/nginx:latest@sha256:<digest>
§Examples
use docker_image::DockerImage;
let image: DockerImage = "nginx:latest".parse().unwrap();
assert_eq!(image.name, "nginx");
assert_eq!(image.tag, Some("latest".to_string()));
assert_eq!(image.digest, None);
Source§type Err = DockerImageError
type Err = DockerImageError
The associated error which can be returned from parsing.
Source§impl PartialEq for DockerImage
impl PartialEq for DockerImage
Source§impl TryFrom<&str> for DockerImage
impl TryFrom<&str> for DockerImage
Source§impl TryFrom<String> for DockerImage
impl TryFrom<String> for DockerImage
impl StructuralPartialEq for DockerImage
Auto Trait Implementations§
impl Freeze for DockerImage
impl RefUnwindSafe for DockerImage
impl Send for DockerImage
impl Sync for DockerImage
impl Unpin for DockerImage
impl UnwindSafe for DockerImage
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
Mutably borrows from an owned value. Read more