Skip to content

Commit

Permalink
chore(docs): Add examples to Marshal module (#2014)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
  • Loading branch information
spotandjake and phated committed Mar 2, 2024
1 parent dde62d3 commit 588a3b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stdlib/marshal.gr
Expand Up @@ -3,6 +3,10 @@
*
* @example from "marshal" include Marshal
*
* @example Marshal.marshal(1)
* @example Marshal.marshal("Hello World")
* @example Marshal.unmarshal(b"\x03\x00\x00\x00")
*
* @since v0.5.3
*/
module Marshal
Expand Down Expand Up @@ -418,6 +422,9 @@ let marshal = (value, buf) => {
* @param value: The value to serialize
* @returns A byte-based representation of the value
*
* @example Marshal.marshal(1) == b"\x03\x00\x00\x00"
* @example Marshal.marshal("馃尵") == Marshal.marshal("馃尵")
*
* @since v0.5.3
*/
@unsafe
Expand Down Expand Up @@ -1047,6 +1054,9 @@ let unmarshal = buf => {
* @param bytes: The data to deserialize
* @returns An in-memory value
*
* @example Marshal.unmarshal(Marshal.marshal('馃尵')) == Ok('馃尵')
* @example Marshal.unmarshal(b"\x03\x00\x00\x00") == Ok(1)
*
* @since v0.5.3
*/
@unsafe
Expand Down
32 changes: 32 additions & 0 deletions stdlib/marshal.md
Expand Up @@ -13,6 +13,18 @@ No other changes yet.
from "marshal" include Marshal
```

```grain
Marshal.marshal(1)
```

```grain
Marshal.marshal("Hello World")
```

```grain
Marshal.unmarshal(b"\x03\x00\x00\x00")
```

## Values

Functions and constants included in the Marshal module.
Expand Down Expand Up @@ -44,6 +56,16 @@ Returns:
|----|-----------|
|`Bytes`|A byte-based representation of the value|

Examples:

```grain
Marshal.marshal(1) == b"\x03\x00\x00\x00"
```

```grain
Marshal.marshal("馃尵") == Marshal.marshal("馃尵")
```

### Marshal.**unmarshal**

<details disabled>
Expand Down Expand Up @@ -74,3 +96,13 @@ Returns:
|----|-----------|
|`Result<a, String>`|An in-memory value|

Examples:

```grain
Marshal.unmarshal(Marshal.marshal('馃尵')) == Ok('馃尵')
```

```grain
Marshal.unmarshal(b"\x03\x00\x00\x00") == Ok(1)
```

0 comments on commit 588a3b8

Please sign in to comment.