de-cycle conduit_macros from conduit_core.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
d7d874f88d
commit
7d487d53d8
5 changed files with 28 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -717,7 +717,6 @@ dependencies = [
|
|||
name = "conduit_macros"
|
||||
version = "0.4.5"
|
||||
dependencies = [
|
||||
"conduit_core",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
|
|
|
@ -18,7 +18,6 @@ proc-macro = true
|
|||
syn.workspace = true
|
||||
quote.workspace = true
|
||||
proc-macro2.workspace = true
|
||||
conduit-core.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use conduit_core::utils::string::camel_to_snake_string;
|
||||
use proc_macro::{Span, TokenStream};
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, AttributeArgs, Fields, Ident, ItemEnum, Variant};
|
||||
|
||||
use crate::utils::camel_to_snake_string;
|
||||
|
||||
pub(super) fn command_dispatch(args: TokenStream, input_: TokenStream) -> TokenStream {
|
||||
let input = input_.clone();
|
||||
let item = parse_macro_input!(input as ItemEnum);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
mod admin;
|
||||
mod utils;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
|
|
25
src/macros/utils.rs
Normal file
25
src/macros/utils.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#[must_use]
|
||||
pub(crate) fn camel_to_snake_string(s: &str) -> String {
|
||||
let mut output = String::with_capacity(
|
||||
s.chars()
|
||||
.fold(s.len(), |a, ch| a.saturating_add(usize::from(ch.is_ascii_uppercase()))),
|
||||
);
|
||||
|
||||
let mut state = false;
|
||||
s.chars().for_each(|ch| {
|
||||
let m = ch.is_ascii_uppercase();
|
||||
let s = exchange(&mut state, !m);
|
||||
if m && s {
|
||||
output.push('_');
|
||||
}
|
||||
output.push(ch.to_ascii_lowercase());
|
||||
});
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
pub(crate) fn exchange<T: Clone>(state: &mut T, source: T) -> T {
|
||||
let ret = state.clone();
|
||||
*state = source;
|
||||
ret
|
||||
}
|
Loading…
Add table
Reference in a new issue