Struct DockerImage

Source
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 like my-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

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DockerImage

Source§

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

Source§

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

The associated error which can be returned from parsing.
Source§

impl PartialEq for DockerImage

Source§

fn eq(&self, other: &DockerImage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for DockerImage

Source§

type Error = DockerImageError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for DockerImage

Source§

type Error = DockerImageError

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for DockerImage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.