cyclone-attributes 0.1.0

The official Cyclone attributes: #[network] and #[codec] markers that cyclonec reads. No runtime, no encode, no codec generation.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 24.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 49.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • fomoxa/attributes-rust
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Thang-HaDuy

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

[dependencies]
cyclone-attributes = "1.0"
use cyclone_attributes::*;

#[network]
#[codec]
struct DeviceState {
    #[network(u32)]
    #[codec(edge, unity)]
    id: u32,

    #[network(f32)]
    #[codec(edge)]
    temperature: f32,

    #[network(string)]
    #[codec(unity)]
    display_name: String,
}

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:

#[network(u32)]
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:

#[codec(edge, unity, admin)]
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:

struct DeviceState {
    id: u32,
    temperature: f32,
    display_name: String,
}

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, no Writer, no Limits, no DecodeError.
  • No encode or decode. No Encode, no Decode, 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