cyclone-attributes
The official Cyclone attributes for Rust: #[network] and #[codec].
cyclone-attributes → your source → cyclonec → generated code
This crate defines the two attributes and does nothing with them. It is the
syntax half of Cyclone — the part that makes annotated Rust compile, so that
cyclonec has something to read.
Usage
[]
= "1.0"
use *;
The attributes
| Where | Attribute | Says |
|---|---|---|
| model | #[network] |
this struct is a Cyclone network model |
| model | #[codec] |
this model takes part in codec generation |
| field | #[network(TYPE)] |
this field's Cyclone wire type |
| field | #[codec(a, b, …)] |
the codec profiles this field belongs to |
A model may carry either marker, or both, in either order.
#[network(TYPE)] — the declared type is the schema
cyclonec believes the attribute and never infers a Cyclone type from the Rust
type. So this:
value: u64,
declares a u32 on the wire, whatever the Rust field says. Whether the two are
compatible is a question for cyclonec's validation, later. This crate does not
ask it.
#[codec(...)] — profiles are names you invent
A field may belong to one profile or to many, with no limit, in the order you wrote them:
id: u32,
edge, unity, server, client, orange_pi, godot — none of these are
Cyclone concepts. They are identifiers you choose, and this crate holds no
list of them, no default, and no opinion. Grouping fields by profile is
cyclonec's job, done by reading your source.
What it does
The attributes are inert markers. Applied to an item, they remove themselves and every Cyclone attribute inside it, and hand back the item otherwise untouched — same fields, same types, same derives, same doc comments, same spans. The struct above compiles to exactly:
That removal is the entire implementation, and it exists for one narrow reason:
Rust does not allow an attribute macro on a field, so #[network(u32)] cannot
compile on its own. An attribute on the struct is what makes the ones on its
fields legal, by consuming them.
What it does not do
Everything else.
- No runtime. No
Reader, noWriter, noLimits, noDecodeError. - No encode or decode. No
Encode, noDecode, no serialization of any kind. - No codec generation. Nothing is emitted but the item you wrote.
- No parser, no IR, no type system, no codec discovery.
- No registry, no reflection, no dynamic dispatch.
- No dependencies. Not one, and nothing here could need one.
It reads no Cyclone type, validates no annotation, and knows no codec name.
Every semantic question — what u32 means, whether a u64 field may carry it,
what edge covers — belongs to cyclonec, which reads the annotations out of
your source, not out of this crate's expansion.
This is not a serialization runtime and not a networking library. It is two attributes and the code that takes them back off.
Where it sits
cyclone-attributes
│ defines attributes, and nothing else
▼
User Source
│
▼
cyclonec
├── Parser
├── IR
├── Type System
├── Codec discovery
└── Code Generator
│
▼
Generated Source
├── Reader
├── Writer
├── DecodeError
├── Limits
├── EdgeCodec
├── UnityCodec
└── …
This crate knows nothing about anything below it.
Tests
tests/attributes.rs covers every case in the specification: each marker alone
and both together, in either order; the declared field types; one profile and
many; several fields across different profiles; and profile names invented for
the test that the crate has never heard of.
Every one of them is really a compilation test — an attribute that failed to consume its field attributes would not reach an assertion, because the file would not build.
cargo test
There are no encode or decode tests here, because there is nothing here to encode with.
License
MIT