From 655b823d13acbb71bb1496df29a9008e1b0ee9a2 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 19 Sep 2020 23:15:33 +0200 Subject: Implement Display for Version in build.rs Previously, we implemented the std::string::ToString trait for the Version enum in build.rs for converting the libnitrokey version number to a string. This patch replaces this implementation with an implementation of the std::fmt::Display trait, which automatically generates a ToString implementation and is more idiomatic. --- build.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'build.rs') diff --git a/build.rs b/build.rs index a9d0778..24fdf0a 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,9 @@ use std::env; +use std::fmt; use std::fs; use std::io; use std::io::{Read, Write}; use std::path; -use std::string; use cc; @@ -14,12 +14,13 @@ struct Version { patch: Option, } -impl string::ToString for Version { - fn to_string(&self) -> String { - match self.patch { - Some(patch) => format!("v{}.{}.{}", self.major, self.minor, patch), - None => format!("v{}.{}", self.major, self.minor), +impl fmt::Display for Version { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "v{}.{}", self.major, self.minor)?; + if let Some(patch) = self.patch { + write!(f, ".{}", patch)?; } + Ok(()) } } -- cgit v1.2.1