From 1026b8183b1aa8fe243fee57dd351aa92636eda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Duarte?= Date: Thu, 15 Aug 2024 16:14:27 +0100 Subject: [PATCH] fix: remove dependency on heck --- Cargo.lock | 7 ------- Cargo.toml | 1 - src/lib.rs | 23 +++++++++++++++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7e4c08..53ce67b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,12 +30,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "itoa" version = "1.0.10" @@ -76,7 +70,6 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" name = "sealed" version = "0.5.0" dependencies = [ - "heck", "proc-macro2", "quote", "syn", diff --git a/Cargo.toml b/Cargo.toml index fb2173d..f439e12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 8fc771b..93efff3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -216,9 +215,29 @@ fn parse_sealed_impl(item_impl: &syn::ItemImpl) -> syn::Result { }) } +/// Convert a string into snake case. +/// +/// Stolen't from +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(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