Expand description
§objs
objs is a tiny macro library for creating named and unnamed
(anonymous) struct-backed objects on the fly, without having to
declare a struct up front.
It provides three macros:
obj!— build an anonymous, explicitly-typed object (great for one-off values, test fixtures, or small “record” types).infer_obj!— build an anonymous object whose field types are inferred generically from the values you give it.let_obj!— declare a named struct type and bind an instance of it to a local variable (with the same name as the type) in a single expression, optionally mutable, optionally withimplblocks.
All three macros expand to a real, ordinary Rust struct under the
hood, so the objects you get back are fully-typed, zero-cost, and can
implement traits like any other struct.
§Quick example
use objs::obj;
let point = obj! {
x: i32 = 10,
y: i32 = 20,
};
assert_eq!(point.x, 10);
assert_eq!(point.y, 20);