`Val::frac` for fractional value units
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
`Val::Percent` exists, but it's on a scale of `0.0 - 100.0` which feels unnatural considering fractional values are typically from `0.0 - 1.0`. But this makes sense, since it's a *percentage*. This proposes a helper function on Val, `pub fn frac(f: f32) -> Val`, making a `Val::Percent`.
## What solution would you like?
```rs
impl Val {
pub fn frac(f: f32) -> Self {
Self::Percent(f * 100.0)
}
}
```
## What alternative(s) have you considered?
- Just using `Percent` but again this feels unnatural
- Implementing that helper function myself:
```rs
pub trait ValFrac {
fn frac(f: f32) -> Self;
}
impl ValFrac for Val {
fn frac(f: f32) -> Self {
Self::Percent(f * 100.0)
}
}
```
## Additional context
Contributor guide
Assessment
This issue has not been assessed yet.