MCPcopy Create free account
hub / github.com/csskit/csskit / structure_with_prefix

Function structure_with_prefix

crates/csskit_derives/src/semantic_eq.rs:7–16  ·  view source on GitHub ↗
(input: &'a DeriveInput, prefix: &'static str)

Source from the content-addressed store, hash-verified

5use synstructure::{AddBounds, BindStyle, Structure};
6
7fn structure_with_prefix<'a>(input: &'a DeriveInput, prefix: &'static str) -> Result<Structure<'a>> {
8 let mut s = Structure::try_new(input)?;
9 s.add_bounds(AddBounds::None);
10 s.bind_with(|_| BindStyle::Move);
11 s.binding_name(move |field, i| match &field.ident {
12 Some(name) => format_ident!("{prefix}_{name}"),
13 None => format_ident!("{prefix}{i}"),
14 });
15 Ok(s)
16}
17
18pub fn derive(input: DeriveInput) -> Result<TokenStream> {
19 if let Data::Struct(ref s) = input.data

Callers 1

deriveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected