repe_core/lib.rs
1//! The `RepeStruct` surface of [`repe`], on its own.
2//!
3//! A served struct's endpoints are declared where the *type* is declared, and
4//! that is not always the crate that runs the RPC. A pure-logic crate — no I/O,
5//! no `unsafe`, buildable on any host, and often kept that way deliberately —
6//! should not have to acquire a server, a client, and a transport just to
7//! publish a couple of paths. Its choices without this crate were to derive
8//! nothing and concede the sub-paths, or to take the whole dependency.
9//!
10//! So this carries the four things a type needs to *be* served and nothing that
11//! serves it:
12//!
13//! * [`RepeStruct`], the dispatch trait, and [`RepeMethods`], the method table
14//! `#[repe::methods]` generates beside it;
15//! * [`StructError`], what a handler reports;
16//! * [`ResponseBody`], what a read encodes into;
17//! * [`constants`], the protocol enums those two name.
18//!
19//! `repe` re-exports every one of them at the same paths, so a type derived
20//! against this crate mounts on a `repe::Router` with nothing in between, and
21//! `#[derive(RepeStruct)]` resolves its generated paths against whichever of the
22//! two crates it finds.
23//!
24//! ```
25//! use repe_core::RepeStruct;
26//!
27//! #[derive(serde::Serialize, serde::Deserialize, RepeStruct)]
28//! struct Build {
29//! version: String,
30//! revision: u64,
31//! }
32//! ```
33//!
34//! [`repe`]: https://docs.rs/repe
35//! [`RepeMethods`]: structs::RepeMethods
36
37// Lets the derive macros emit `::repe_core` paths that resolve inside this crate
38// as well as outside it. See `repe_derive::repe_crate_path`.
39extern crate self as repe_core;
40
41pub mod constants;
42pub mod structs;
43
44pub use constants::{BodyFormat, ErrorCode, HEADER_SIZE, QueryFormat, REPE_SPEC, REPE_VERSION};
45pub use structs::{RepeStruct, ResponseBody, StructError};
46
47/// Derive macro generating a [`structs::RepeStruct`] implementation from a
48/// struct's fields.
49pub use repe_derive::RepeStruct;
50
51/// Attribute macro that publishes every method of an inherent `impl` block,
52/// generating the [`structs::RepeMethods`] table from the signatures themselves.
53///
54/// Pair it with `#[repe(methods)]` on the `#[derive(RepeStruct)]` struct; each
55/// half asserts the other, so neither can be forgotten silently.
56pub use repe_derive::methods;