11use serde:: { Deserialize , Serialize } ;
22use std:: collections:: HashMap ;
3+ use std:: fmt:: Display ;
34
45#[ derive( Debug , Clone , Serialize , Deserialize ) ]
56pub struct DockerfileConfig {
@@ -80,16 +81,16 @@ impl DockerfileConfig {
8081 let mut content = format ! ( "FROM {}\n " , self . base_image) ;
8182
8283 for command in & self . commands {
83- content. push_str ( & format ! ( "{}\n " , command. to_string ( ) ) ) ;
84+ content. push_str ( & format ! ( "{}\n " , command) ) ;
8485 }
8586
8687 content
8788 }
8889}
8990
90- impl ToString for DockerCommand {
91- fn to_string ( & self ) -> String {
92- match self {
91+ impl Display for DockerCommand {
92+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
93+ let str = match self {
9394 DockerCommand :: Add {
9495 sources,
9596 dest,
@@ -174,7 +175,7 @@ impl ToString for DockerCommand {
174175 format ! ( "LABEL {}" , labels)
175176 }
176177 DockerCommand :: Maintainer { name } => format ! ( "MAINTAINER {}" , name) ,
177- DockerCommand :: Onbuild { command } => format ! ( "ONBUILD {}" , command. to_string ( ) ) ,
178+ DockerCommand :: Onbuild { command } => format ! ( "ONBUILD {}" , command) ,
178179 DockerCommand :: Run { command } => format ! ( "RUN {}" , command) ,
179180 DockerCommand :: Shell { shell } => format ! ( "SHELL {}" , shell_words:: join( shell) ) ,
180181 DockerCommand :: StopSignal { signal } => format ! ( "STOPSIGNAL {}" , signal) ,
@@ -187,6 +188,7 @@ impl ToString for DockerCommand {
187188 }
188189 DockerCommand :: Volume { paths } => format ! ( "VOLUME {}" , shell_words:: join( paths) ) ,
189190 DockerCommand :: Workdir { path } => format ! ( "WORKDIR {}" , path) ,
190- }
191+ } ;
192+ write ! ( f, "{}" , str )
191193 }
192194}
0 commit comments