Skip to content

Add struct class-level options - #39

Merged
jcrist merged 6 commits into
masterfrom
struct-options
Jul 3, 2021
Merged

Add struct class-level options#39
jcrist merged 6 commits into
masterfrom
struct-options

Conversation

@jcrist

@jcrist jcrist commented Jul 3, 2021

Copy link
Copy Markdown
Member

Adds support for struct class-level options. These can be set as parameters to the metaclass. For example:

import msgspec

class Point(msgspec.Struct, immutable=True):
    x: float
    y: float

The following options are defined:

  • immutable: makes a struct object immutable, and adds a __hash__ implementation.
  • asarray: whether to serialize the struct as an array instead of as a dict.

Todo:

  • Support passing options to the StructMeta metaclass
  • Implement the immutable option
  • Implement encoding Struct instances as arrays if asarray is set
  • Implement decoding Struct instances from arrays if asarray is set
  • Docs

jcrist added 6 commits July 3, 2021 00:05
Adds support for struct class-level options. These can be set as
parameters to the metaclass. For example:

```python
import msgspec

class Point(msgspec.Struct, immutable=True):
    x: float
    y: float
```

Currently these options don't do anything (TODO), but the following
options are defined:

- `immutable`: makes a struct object immutable, and adds a `__hash__`
  implementation.
- `asarray`: whether to serialize the struct as an array instead of as a
  dict.
@jcrist
jcrist merged commit eaa4856 into master Jul 3, 2021
@jcrist
jcrist deleted the struct-options branch July 3, 2021 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant