uint icon indicating copy to clipboard operation
uint copied to clipboard

Support integral padding in formatting directives for Uint

Open cassc opened this issue 1 year ago • 1 comments

Version

1.10.1

Platform

Linux x1us 6.1.41-1-MANJARO #1 SMP PREEMPT_DYNAMIC Tue Jul 25 09:17:30 UTC 2023 x86_64 GNU/Linux

Description

It looks like when formating to hex string, U256::ZERO is handled differently:

    let a = U256::ZERO;
    println!("{:064x}", a); // prints 0, I'd expect 0000000000000000000000000000000000000000000000000000000000000000

    let b = U256::from(1);
    println!("{:064x}", b); // prints 0000000000000000000000000000000000000000000000000000000000000001

Complete minimum runnable project:

https://github.com/cassc/ruint-test/blob/main/src/main.rs

cassc avatar Aug 16 '23 08:08 cassc

We don't currently support any padding directive. 0 is "0" regardless of integer size, and hex strings are always full-width. I don't think this is a high priority, but I'm leaving it open in case we want to support this later

let b = Uint::<1,1>::from(1);
// padding is ignored
println!("{:064x}", b); // prints 01

prestwich avatar Aug 17 '23 15:08 prestwich