Skip to content

Commit

Permalink
impl ToString for ImageIndex, ImageManifest, and ImageConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Jul 27, 2022
1 parent c094550 commit ec774a1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/image/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ impl ImageConfiguration {
}
}

/// Implement `ToString` directly since we cannot avoid twice memory allocation
/// when using auto-implementaion through `Display`.
impl ToString for ImageConfiguration {
fn to_string(&self) -> String {
// Serde seralization never fails since this is
// a combination of String and enums.
self.to_string_pretty()
.expect("ImageConfiguration JSON convertion failed")
}
}

#[derive(
Builder,
Clone,
Expand Down
11 changes: 11 additions & 0 deletions src/image/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ impl Default for ImageIndex {
}
}

/// Implement `ToString` directly since we cannot avoid twice memory allocation
/// when using auto-implementaion through `Display`.
impl ToString for ImageIndex {
fn to_string(&self) -> String {
// Serde seralization never fails since this is
// a combination of String and enums.
self.to_string_pretty()
.expect("ImageIndex to JSON convertion failed")
}
}

#[cfg(test)]
mod tests {
use std::{fs, path::PathBuf};
Expand Down
11 changes: 11 additions & 0 deletions src/image/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ impl ImageManifest {
}
}

/// Implement `ToString` directly since we cannot avoid twice memory allocation
/// when using auto-implementaion through `Display`.
impl ToString for ImageManifest {
fn to_string(&self) -> String {
// Serde seralization never fails since this is
// a combination of String and enums.
self.to_string_pretty()
.expect("ImageManifest to JSON convertion failed")
}
}

#[cfg(test)]
mod tests {
use std::{fs, path::PathBuf};
Expand Down

0 comments on commit ec774a1

Please sign in to comment.