Skip to content

Commit

Permalink
Adding NewSize/NewRate
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Jan 30, 2025
1 parent e69fe60 commit 914c4b9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion size.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func FormatRate(rate Rate, verb rune, prec int, space bool) string {
// Size is a byte size.
type Size int64

// NewSize creates a byte size.
func NewSize[T inti | uinti](size T) Size {
return Size(size)
}

// Format satisfies the [fmt.Formatter] interface. See [AppendSize] for
// recognized verbs.
func (size Size) Format(f fmt.State, verb rune) {
Expand Down Expand Up @@ -204,7 +209,15 @@ type Rate struct {
Unit time.Duration
}

// Format satisfies the [fmt.Formatter] interface. See [AppendSize] for
// NewRate creates a byte rate.
func NewRate[T inti | uinti](size T, unit time.Duration) Rate {
return Rate{
Size: NewSize(size),
Unit: unit,
}
}

// Format satisfies the [fmt.Formatter] interface. See [AppendRate] for
// recognized verbs.
func (rate Rate) Format(f fmt.State, verb rune) {
prec := DefaultSizePrec
Expand Down

0 comments on commit 914c4b9

Please sign in to comment.