Safe Haskell | None |
---|---|
Language | Haskell2010 |
Provides high level formatters for different byte types. This module contains the functions and types for typical usage. Additional functionality (e.g. optics, type classes/families for defining custom formatters) can be found in:
Since: 0.1
Synopsis
- formatSized :: (Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) => BaseFormatter (Raw a) -> SizedFormatter -> a -> Text
- formatSizedDirected :: (Directed a, Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) => BaseFormatter (Raw a) -> SizedFormatter -> DirectedFormatter -> a -> Text
- data CaseFormat
- data IntegralFormatter = MkIntegralFormatter
- newtype FloatingFormatter = MkFloatingFormatter (Maybe Word8)
- data SizeFormat
- data SizedFormatter = MkSizedFormatter CaseFormat Bool SizeFormat
- sizedFormatterUnix :: SizedFormatter
- sizedFormatterNatural :: SizedFormatter
- sizedFormatterVerbose :: SizedFormatter
- data DirectionFormat
- data DirectedFormatter = MkDirectedFormatter CaseFormat DirectionFormat
- directedFormatterUnix :: DirectedFormatter
- directedFormatterVerbose :: DirectedFormatter
- class Default a where
- def :: a
High-level functions
:: (Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) | |
=> BaseFormatter (Raw a) | Formatter to use on the underlying value i.e. |
-> SizedFormatter | Formatter to use on the size units. |
-> a | Value to be formatted. |
-> Text | Result. |
Formats a value with Size
units. Can be used with all byte types
in this package.
Examples
>>>
import Data.Default (Default (..))
>>>
import Data.Bytes (Bytes (..), Size (..), hideSize)
>>>
let bf1 = MkIntegralFormatter
>>>
let b1 = MkBytes @M @Int 7
>>>
formatSized bf1 def b1
"7 mb"
>>>
formatSized bf1 sizedFormatterUnix b1
"7M"
>>>
let bf2 = MkFloatingFormatter (Just 2)
>>>
let b2 = hideSize $ MkBytes @G @Float 20.248
>>>
formatSized bf2 sizedFormatterVerbose b2
"20.25 gigabytes"
Since: 0.1
:: (Directed a, Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) | |
=> BaseFormatter (Raw a) | Formatter to use on the underlying value i.e. |
-> SizedFormatter | Formatter to use on the size units. |
-> DirectedFormatter | Formatter to use on the direction units. |
-> a | Value to be formatted. |
-> Text | Result. |
Formats a value with Size
and
Direction
units. Can only be used when both units
are present.
Examples
>>>
import Data.Default (Default (..))
>>>
import Data.Bytes.Network (Direction (..), NetBytes (..), Size (..))
>>>
import Data.Bytes.Size (Sized (..))
>>>
let bf1 = MkIntegralFormatter
>>>
let b1 = MkNetBytesP @Up @M @Int 7
>>>
formatSizedDirected bf1 def def b1
"7 mb up"
>>>
formatSizedDirected bf1 sizedFormatterUnix directedFormatterUnix b1
"7M U"
>>>
let bf2 = MkFloatingFormatter (Just 2)
>>>
let b2 = hideSize $ MkNetBytesP @Down @G @Float 20.248
>>>
formatSizedDirected bf2 sizedFormatterVerbose directedFormatterVerbose b2
"20.25 gigabytes down"
Since: 0.1
Types
Base
data CaseFormat Source #
Case formatting.
Since: 0.1
CaseFormatLower | Since: 0.1 |
CaseFormatTitle | Since: 0.1 |
CaseFormatUpper | Since: 0.1 |
Instances
Show CaseFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base showsPrec :: Int -> CaseFormat -> ShowS # show :: CaseFormat -> String # showList :: [CaseFormat] -> ShowS # | |
Eq CaseFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base (==) :: CaseFormat -> CaseFormat -> Bool # (/=) :: CaseFormat -> CaseFormat -> Bool # |
data IntegralFormatter Source #
Formatter for integral types.
Since: 0.1
Instances
Formatter IntegralFormatter Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base formatStr :: IntegralFormatter -> Text Source # |
newtype FloatingFormatter Source #
Formatter for floating types. Takes an optional param for rounding digits.
Since: 0.1
Instances
Formatter FloatingFormatter Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base formatStr :: FloatingFormatter -> Text Source # |
Size
data SizeFormat Source #
Determines how to format the size units.
Examples
>>>
def @SizeFormat
SizeFormatMedium
Since: 0.1
SizeFormatShort | Since: 0.1 |
SizeFormatMedium | Since: 0.1 |
SizeFormatLong | Since: 0.1 |
Instances
Default SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size def :: SizeFormat Source # | |
Show SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size showsPrec :: Int -> SizeFormat -> ShowS # show :: SizeFormat -> String # showList :: [SizeFormat] -> ShowS # | |
Eq SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size (==) :: SizeFormat -> SizeFormat -> Bool # (/=) :: SizeFormat -> SizeFormat -> Bool # |
data SizedFormatter Source #
Formatting size units.
Examples
>>>
def @SizedFormatter
MkSizedFormatter {caseFormat = CaseFormatLower, leadingSpace = True, sizeFormat = SizeFormatMedium}
Since: 0.1
Instances
sizedFormatterUnix :: SizedFormatter Source #
Unix-style formatter:
- Upper case.
- No space between value and unit.
- Single letter unit.
For example: 7G
.
Since: 0.1
sizedFormatterNatural :: SizedFormatter Source #
Natural-style formatter:
- Lower case.
- Space between value and unit.
- Two letter units.
For example: 7 gb
.
Since: 0.1
sizedFormatterVerbose :: SizedFormatter Source #
Verbose formatter:
- Lower case.
- Space between value and unit.
- Full spelling.
For example: 7 gigabytes
.
Since: 0.1
Direction
data DirectionFormat Source #
Determines how to format the direction units.
Examples
>>>
def @DirectionFormat
DirectionFormatLong
Since: 0.1
DirectionFormatShort | Since: 0.1 |
DirectionFormatLong | Since: 0.1 |
Instances
Default DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction | |
Show DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction showsPrec :: Int -> DirectionFormat -> ShowS # show :: DirectionFormat -> String # showList :: [DirectionFormat] -> ShowS # | |
Eq DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction (==) :: DirectionFormat -> DirectionFormat -> Bool # (/=) :: DirectionFormat -> DirectionFormat -> Bool # |
data DirectedFormatter Source #
Formats bytes over floating types.
Examples
>>>
def @DirectedFormatter
MkDirectedFormatter {caseFormat = CaseFormatLower, directionFormat = DirectionFormatLong}
Since: 0.1
Instances
directedFormatterUnix :: DirectedFormatter Source #
"unix"-style formatter:
- Upper case.
- Short spelling.
For example: 7 U
.
Since: 0.1
directedFormatterVerbose :: DirectedFormatter Source #
Verbose formatter:
- Lower case.
- Full spelling.
For example: 7 down
.
Since: 0.1
Reexports
class Default a where Source #
A class for types with a default value.
Nothing
The default value for this type.