-
๐ Hi, Iโm @mendelsshop
mendelsshop / loading_bar Goto Github PK
View Code? Open in Web Editor NEWSimple CLI loading bar crate
Home Page: https://crates.io/crates/loading_bar
License: MIT License
Simple CLI loading bar crate
Home Page: https://crates.io/crates/loading_bar
License: MIT License
๐ Hi, Iโm @mendelsshop
When using LoadingBar::auto_run
you can set the length and start parameters to be the same. When the index is calculated in line 102 of src/lib.rs with let index = time_in_seconds as f32 / (len - start) as f32;
, index while be set to inf
because of division by 0. This will crash the program in this line:
line 112 src/lib.rs: self_clone.advance_by_print(start);
thread 'main' panicked at ' You can't advance more than the length of the bar', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/loading_bar-1.0.0/src/lib.rs:139:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I believe this is happening because the program tries to advance by the length of the bar which is larger than the length of the bar. And if the program kept going, the program it would then crash by trying to std::thread::sleep
for inf
seconds.
I guess it might be better to return a Result
so you can tell the caller that they passed invalid parameters, and they can handle the errors themselves.
While playing around with your library, I couldn't get auto_run
to work although everything else did. I'm not sure whether this is just a problem with my computer or not. After looking more at your code for auto_run
, I have a question. When you initialize a loading bar using:
let mut self_clone = LoadingBar {
len,
index: start,
done: false,
color,
space_left: len - start,
half: false,
start_pos,
};
From my understanding, index
keeps track of how far along the bar is, which is why you set it to start
. But, on the next line you call
self_clone.advance_by_print(start);
which increments the index
by start
after it has already been set to start
. I'm posting this issue as a question. Is this supposed to happen? Sorry to bother you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.