Rename ToCamelCase => ToUpperCamelCase, ToMixedCase => ToLowerCamelCase

This commit is contained in:
Jonas Platte
2020-12-30 13:29:07 +01:00
parent c7d97b59e9
commit 6d61baee8a
4 changed files with 30 additions and 28 deletions
+2
View File
@@ -4,3 +4,5 @@ Breaking changes:
* Rename all traits from `SomeCase` to `ToSomeCase`, matching `std`s convention
of beginning trait names with a verb (`ToOwned`, `AsRef`, …)
* Rename `ToMixedCase` to `ToLowerCamelCase`
* Rename `ToCamelCase` to `ToUpperCamelCase`
+4 -4
View File
@@ -40,21 +40,21 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
mod camel;
mod kebab;
mod mixed;
mod lower_camel;
mod shouty_kebab;
mod shouty_snake;
mod snake;
mod title;
mod upper_camel;
pub use camel::ToCamelCase;
pub use kebab::ToKebabCase;
pub use mixed::ToMixedCase;
pub use lower_camel::ToLowerCamelCase;
pub use shouty_kebab::ToShoutyKebabCase;
pub use shouty_snake::{ToShoutySnakeCase, ToShoutySnekCase};
pub use snake::{ToSnakeCase, ToSnekCase};
pub use title::ToTitleCase;
pub use upper_camel::ToUpperCamelCase;
use unicode_segmentation::UnicodeSegmentation;
+12 -12
View File
@@ -1,25 +1,25 @@
use crate::{capitalize, lowercase, transform};
/// This trait defines a mixed case conversion.
/// This trait defines a lower camel case conversion.
///
/// In mixedCase, word boundaries are indicated by capital letters, excepting
/// the first word.
/// In lowerCamelCase, word boundaries are indicated by capital letters,
/// excepting the first word.
///
/// ## Example:
///
/// ```rust
/// use heck::ToMixedCase;
/// use heck::ToLowerCamelCase;
///
/// let sentence = "It is we who built these palaces and cities.";
/// assert_eq!(sentence.to_mixed_case(), "itIsWeWhoBuiltThesePalacesAndCities");
/// assert_eq!(sentence.to_lower_camel_case(), "itIsWeWhoBuiltThesePalacesAndCities");
/// ```
pub trait ToMixedCase: ToOwned {
/// Convert this type to mixed case.
fn to_mixed_case(&self) -> Self::Owned;
pub trait ToLowerCamelCase: ToOwned {
/// Convert this type to lower camel case.
fn to_lower_camel_case(&self) -> Self::Owned;
}
impl ToMixedCase for str {
fn to_mixed_case(&self) -> String {
impl ToLowerCamelCase for str {
fn to_lower_camel_case(&self) -> String {
transform(
self,
|s, out| {
@@ -36,13 +36,13 @@ impl ToMixedCase for str {
#[cfg(test)]
mod tests {
use super::ToMixedCase;
use super::ToLowerCamelCase;
macro_rules! t {
($t:ident : $s1:expr => $s2:expr) => {
#[test]
fn $t() {
assert_eq!($s1.to_mixed_case(), $s2)
assert_eq!($s1.to_lower_camel_case(), $s2)
}
};
}
+12 -12
View File
@@ -1,38 +1,38 @@
use crate::{capitalize, transform};
/// This trait defines a camel case conversion.
/// This trait defines an upper camel case conversion.
///
/// In CamelCase, word boundaries are indicated by capital letters, including
/// the first word.
/// In UpperCamelCase, word boundaries are indicated by capital letters,
/// including the first word.
///
/// ## Example:
///
/// ```rust
/// use heck::ToCamelCase;
/// use heck::ToUpperCamelCase;
///
/// let sentence = "We are not in the least afraid of ruins.";
/// assert_eq!(sentence.to_camel_case(), "WeAreNotInTheLeastAfraidOfRuins");
/// assert_eq!(sentence.to_upper_camel_case(), "WeAreNotInTheLeastAfraidOfRuins");
/// ```
pub trait ToCamelCase: ToOwned {
/// Convert this type to camel case.
fn to_camel_case(&self) -> Self::Owned;
pub trait ToUpperCamelCase: ToOwned {
/// Convert this type to upper camel case.
fn to_upper_camel_case(&self) -> Self::Owned;
}
impl ToCamelCase for str {
fn to_camel_case(&self) -> String {
impl ToUpperCamelCase for str {
fn to_upper_camel_case(&self) -> String {
transform(self, capitalize, |_| {})
}
}
#[cfg(test)]
mod tests {
use super::ToCamelCase;
use super::ToUpperCamelCase;
macro_rules! t {
($t:ident : $s1:expr => $s2:expr) => {
#[test]
fn $t() {
assert_eq!($s1.to_camel_case(), $s2)
assert_eq!($s1.to_upper_camel_case(), $s2)
}
};
}