#macro-derive #macro #struct-fields #derive #generate #splat

macro splat_derive

A crate providing a Splat derive macro, which generates a splat method for the struct deriving it

2 releases

0.1.1 Jan 14, 2024
0.1.0 Jan 14, 2024

#528 in Procedural macros

22 downloads per month

MIT/Apache

7KB
51 lines

About

This is a crate providing a Splat derive macro, which generates a splat method for the struct deriving it.

The splat method

The splat method is commonly defined for structs with numeric fields of the same type. It takes a value v and returns an instance of the struct where each field is set to v.

This crate provides a macro that generates a splat method for any struct that has fields which are all of the same type. However, the type shared by each field must implement Clone.

Usage

Add the following to your Cargo.toml

[dependencies]
splat_derive = "0.1.0"

lib.rs:

A crate providing a [Splat] derive macro, which generates a splat method for the struct deriving it.

The splat method

The splat method is commonly defined for structs with numeric fields of the same type. It takes a value v and returns an instance of the struct where each field is set to v.

This crate provides a macro that generates a splat method for any struct that has fields which are all of the same type. However, the type shared by each field must implement [Clone].

Dependencies

~320–770KB
~18K SLoC