Skip to content

Commit

Permalink
fix: remove dependency on heck
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed Aug 15, 2024
1 parent b9fe92b commit 1026b81
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ syn = { version = "2.0", features = ["extra-traits"] }
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
heck = "0.4"
23 changes: 21 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@

use std::fmt;

use heck::ToSnakeCase as _;
use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{format_ident, quote};
Expand Down Expand Up @@ -216,9 +215,29 @@ fn parse_sealed_impl(item_impl: &syn::ItemImpl) -> syn::Result<TokenStream2> {
})
}

/// Convert a string into snake case.
///
/// Stolen't from <https://github.com/jmg-duarte/sealed-rs/pull/6#pullrequestreview-653837118>
fn to_snake_case(s: &'_ str) -> String {
let mut ret = String::with_capacity(s.len());
let mut first = true;
s.bytes().for_each(|c| {
if c.is_ascii_uppercase() {
if !first {
ret.push('_');
}
ret.push(c.to_ascii_lowercase() as char);
} else {
ret.push(c as char);
}
first = false;
});
ret
}

/// Constructs [`syn::Ident`] of a sealing module name.
fn seal_name<D: fmt::Display>(seal: D) -> syn::Ident {
format_ident!("__seal_{}", &seal.to_string().to_snake_case())
format_ident!("__seal_{}", to_snake_case(&seal.to_string()))
}

/// Arguments accepted by `#[sealed]` attribute when placed on a trait
Expand Down

0 comments on commit 1026b81

Please sign in to comment.