Skip to content

Commit c0ac296

Browse files
committed
[Rust] Impl Display for VersionInfo
1 parent 0e1cc65 commit c0ac296

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

rust/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ use rc::Ref;
104104
use std::cmp;
105105
use std::collections::HashMap;
106106
use std::ffi::{c_char, c_void, CStr};
107+
use std::fmt::{Display, Formatter};
107108
use std::path::{Path, PathBuf};
108109
use string::BnString;
109110
use string::IntoCStr;
@@ -513,6 +514,20 @@ impl Ord for VersionInfo {
513514
}
514515
}
515516

517+
impl Display for VersionInfo {
518+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
519+
if self.channel.is_empty() {
520+
write!(f, "{}.{}.{}", self.major, self.minor, self.build)
521+
} else {
522+
write!(
523+
f,
524+
"{}.{}.{}-{}",
525+
self.major, self.minor, self.build, self.channel
526+
)
527+
}
528+
}
529+
}
530+
516531
pub fn version_info() -> VersionInfo {
517532
let info_raw = unsafe { BNGetVersionInfo() };
518533
VersionInfo::from_owned_raw(info_raw)

0 commit comments

Comments
 (0)