Fix semver breaking Display change of ChildNumber

Fixes #608. In #567 the Display impl for ChildNumber was
consciously changed, assuming the semver break would not
affect any correctly implemented downstream projects. We
were wrong.
This commit is contained in:
Sebastian Geisler 2021-06-08 15:19:01 +02:00
parent f11f09d55b
commit 091ac89440
1 changed files with 5 additions and 5 deletions

View File

@ -172,7 +172,7 @@ impl fmt::Display for ChildNumber {
ChildNumber::Hardened { index } => { ChildNumber::Hardened { index } => {
fmt::Display::fmt(&index, f)?; fmt::Display::fmt(&index, f)?;
let alt = f.alternate(); let alt = f.alternate();
f.write_str(if alt { "'" } else { "h" }) f.write_str(if alt { "h" } else { "'" })
}, },
ChildNumber::Normal { index } => fmt::Display::fmt(&index, f), ChildNumber::Normal { index } => fmt::Display::fmt(&index, f),
} }
@ -1070,10 +1070,10 @@ mod tests {
#[test] #[test]
fn fmt_child_number() { fn fmt_child_number() {
assert_eq!("000005'", &format!("{:#06}", ChildNumber::from_hardened_idx(5).unwrap())); assert_eq!("000005h", &format!("{:#06}", ChildNumber::from_hardened_idx(5).unwrap()));
assert_eq!("5'", &format!("{:#}", ChildNumber::from_hardened_idx(5).unwrap())); assert_eq!("5h", &format!("{:#}", ChildNumber::from_hardened_idx(5).unwrap()));
assert_eq!("000005h", &format!("{:06}", ChildNumber::from_hardened_idx(5).unwrap())); assert_eq!("000005'", &format!("{:06}", ChildNumber::from_hardened_idx(5).unwrap()));
assert_eq!("5h", &format!("{}", ChildNumber::from_hardened_idx(5).unwrap())); assert_eq!("5'", &format!("{}", ChildNumber::from_hardened_idx(5).unwrap()));
assert_eq!("42", &format!("{}", ChildNumber::from_normal_idx(42).unwrap())); assert_eq!("42", &format!("{}", ChildNumber::from_normal_idx(42).unwrap()));
assert_eq!("000042", &format!("{:06}", ChildNumber::from_normal_idx(42).unwrap())); assert_eq!("000042", &format!("{:06}", ChildNumber::from_normal_idx(42).unwrap()));
} }