DataDog/glommio

storage example file_size flag has problem

yorkz1994 opened this issue · 0 comments

When I run storage example with flag --size-gb, it always panic no matter what number is set.

./storage --dir /test --size-gb 10
...
Mismatch between definition and access of `file_size`. Could not downcast to TypeId { t: (11446210613632762899, 3222440509213045925) }, need to downcast to TypeId { t: (32853015933574672, 13565291224083057261) }

It turns out that the file_size flag definition has problem.
It misses clap value_parser to convert the input number from string to u64.

The fix is to add value_parser like below:

diff --git a/examples/storage.rs b/examples/storage.rs
index 8beb8ed..de6d7e9 100644
--- a/examples/storage.rs
+++ b/examples/storage.rs
@@ -1,5 +1,5 @@
 use byte_unit::{Byte, UnitType};
-use clap::{Arg, Command};
+use clap::{value_parser, Arg, Command};
 use futures_lite::{
     stream::{self, StreamExt},
     AsyncReadExt, AsyncWriteExt,
@@ -297,6 +297,7 @@ fn main() {
                 .long("size-gb")
                 .action(clap::ArgAction::Set)
                 .required(false)
+                .value_parser(value_parser!(u64))
                 .help("size of the file in GB (default: 2 * memory_size)"),
         )
         .get_matches();