summaryrefslogtreecommitdiff
path: root/cros_alsa/cros_alsa_derive/src/lib.rs
blob: 9970de782ff4c6510e7c1db91fe1efb365c73acf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! `cros_alsa_derive` crate provides derive macros for cros_alsa.
//!

#![deny(missing_docs)]
extern crate proc_macro;

use proc_macro::TokenStream;

mod common;
mod control;
use self::control::impl_control_ops;

#[proc_macro_derive(ControlOps, attributes(cros_alsa))]
/// Derive macro generating an impl of the trait ControlOps.
/// To use this derive macro, users should hold `Ctl` and `ElemID` as `handle`
/// and `id` in their control structure.
pub fn control_ops_derive(input: TokenStream) -> TokenStream {
    match syn::parse(input) {
        Ok(ast) => impl_control_ops(&ast),
        Err(e) => e.to_compile_error().into(),
    }
}