Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Add examples to Marshal module #2014

Merged
merged 3 commits into from Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -419,6 +423,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 @@ -1032,6 +1039,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)
```