ron-hs-0.4.0: RON format implementation in haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Ron.Serialize

Description

Definitions for serializing values into bytes. When serializing, you must choose a formatting option defined at SerializeSettings

Synopsis

Documentation

encode :: ToRon a => SerializeSettings -> a -> ByteString Source #

Serialize a value to a lazy bytestring. For settings you can use haskellStyle or rustStyle or compactStyle

encodeFile :: ToRon a => SerializeSettings -> FilePath -> a -> IO () Source #

Serialize a value into a file. For settings you can use haskellStyle or rustStyle or compactStyle

dumps :: SerializeSettings -> Value -> ByteString Source #

Serialize a RON value to a lazy bytestring. You probably want to use encode instead

dumpFile :: SerializeSettings -> FilePath -> Value -> IO () Source #

Serialize a RON value into a file. You probably want to use encodeFile instead

Style options

data SerializeSettings Source #

Constructors

SerializeSettings 

Fields

  • commaStyle :: !CommaStyle

    How to separate values in compounds (tuples, records, maps, lists)

  • indent :: !Int

    Amount of spaces to indent with. Setting this to zero also disables line breaks

  • singleElementSpecial :: !Bool

    When a compound type only contains one element, this compound value is printed on one line

  • unpackToplevel :: !Bool

    Toplevel record and list are unpacked to not include the constructor and brackets. This is useful for human-consumed files, and looks similar to yaml but with commas. Warning: ron-rs doesn't support reading this

  • openBracketOnSameLine :: !Bool

    For compound types, does the opening bracket go on a new line or stays on the same line as the constructor

  • closeBracketOnSameLine :: !Bool

    For compound types, does the closing bracket go on a new line or stays on the same line as the last element. Setting this to True is a popular default in some haskell autoformat programs

  • spaceAfterColon :: !Bool

    Should a space character be put after colon in records and maps. Useful as False for compact representation

haskellStyle :: SerializeSettings Source #

Style similar to what is produced in haskell with stylish-haskell or hindent.

  • Uses indent size of 4
  • Unpacks top level values

rustStyle :: SerializeSettings Source #

Style similar to what is produced by rustfmt, or by ron-rs itself

compactStyle :: SerializeSettings Source #

All whitespace is disabled. Does not unpack toplevel for compatability, so you can set that if you want an even compacter style that can't be read by ron-rs

data CommaStyle Source #

Style of comma in compound values

Constructors

CommaHistoric

Like in json, comma after value without trailing

CommaTrailing

Comma after value, including last element

CommaLeading

Haskell style, comma at line start

Low-level builders

ronBuilder :: SerializeSettings -> Value -> Builder Source #

The builder producing the serialized representation. You can use this to write ron to outputs not supported by this library, like pipes or conduits