mirror of
https://github.com/openharmony/third_party_rust_heck.git
synced 2026-07-01 20:36:55 -04:00
Rename all traits from SomeCase to ToSomeCase
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# 0.4.0 (unreleased)
|
||||
|
||||
Breaking changes:
|
||||
|
||||
* Rename all traits from `SomeCase` to `ToSomeCase`, matching `std`s convention
|
||||
of beginning trait names with a verb (`ToOwned`, `AsRef`, …)
|
||||
+4
-4
@@ -8,17 +8,17 @@ use crate::{capitalize, transform};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::CamelCase;
|
||||
/// use heck::ToCamelCase;
|
||||
///
|
||||
/// let sentence = "We are not in the least afraid of ruins.";
|
||||
/// assert_eq!(sentence.to_camel_case(), "WeAreNotInTheLeastAfraidOfRuins");
|
||||
/// ```
|
||||
pub trait CamelCase: ToOwned {
|
||||
pub trait ToCamelCase: ToOwned {
|
||||
/// Convert this type to camel case.
|
||||
fn to_camel_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl CamelCase for str {
|
||||
impl ToCamelCase for str {
|
||||
fn to_camel_case(&self) -> String {
|
||||
transform(self, capitalize, |_| {})
|
||||
}
|
||||
@@ -26,7 +26,7 @@ impl CamelCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CamelCase;
|
||||
use super::ToCamelCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
+4
-4
@@ -7,17 +7,17 @@ use crate::{lowercase, transform};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::KebabCase;
|
||||
/// use heck::ToKebabCase;
|
||||
///
|
||||
/// let sentence = "We are going to inherit the earth.";
|
||||
/// assert_eq!(sentence.to_kebab_case(), "we-are-going-to-inherit-the-earth");
|
||||
/// ```
|
||||
pub trait KebabCase: ToOwned {
|
||||
pub trait ToKebabCase: ToOwned {
|
||||
/// Convert this type to kebab case.
|
||||
fn to_kebab_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl KebabCase for str {
|
||||
impl ToKebabCase for str {
|
||||
fn to_kebab_case(&self) -> Self::Owned {
|
||||
transform(self, lowercase, |s| s.push('-'))
|
||||
}
|
||||
@@ -25,7 +25,7 @@ impl KebabCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::KebabCase;
|
||||
use super::ToKebabCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
+7
-7
@@ -47,13 +47,13 @@ mod shouty_snake;
|
||||
mod snake;
|
||||
mod title;
|
||||
|
||||
pub use camel::CamelCase;
|
||||
pub use kebab::KebabCase;
|
||||
pub use mixed::MixedCase;
|
||||
pub use shouty_kebab::ShoutyKebabCase;
|
||||
pub use shouty_snake::{ShoutySnakeCase, ShoutySnekCase};
|
||||
pub use snake::{SnakeCase, SnekCase};
|
||||
pub use title::TitleCase;
|
||||
pub use camel::ToCamelCase;
|
||||
pub use kebab::ToKebabCase;
|
||||
pub use mixed::ToMixedCase;
|
||||
pub use shouty_kebab::ToShoutyKebabCase;
|
||||
pub use shouty_snake::{ToShoutySnakeCase, ToShoutySnekCase};
|
||||
pub use snake::{ToSnakeCase, ToSnekCase};
|
||||
pub use title::ToTitleCase;
|
||||
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
|
||||
+4
-4
@@ -8,17 +8,17 @@ use crate::{capitalize, lowercase, transform};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::MixedCase;
|
||||
/// use heck::ToMixedCase;
|
||||
///
|
||||
/// let sentence = "It is we who built these palaces and cities.";
|
||||
/// assert_eq!(sentence.to_mixed_case(), "itIsWeWhoBuiltThesePalacesAndCities");
|
||||
/// ```
|
||||
pub trait MixedCase: ToOwned {
|
||||
pub trait ToMixedCase: ToOwned {
|
||||
/// Convert this type to mixed case.
|
||||
fn to_mixed_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl MixedCase for str {
|
||||
impl ToMixedCase for str {
|
||||
fn to_mixed_case(&self) -> String {
|
||||
transform(
|
||||
self,
|
||||
@@ -36,7 +36,7 @@ impl MixedCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::MixedCase;
|
||||
use super::ToMixedCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
+4
-4
@@ -8,17 +8,17 @@ use crate::{transform, uppercase};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::ShoutyKebabCase;
|
||||
/// use heck::ToShoutyKebabCase;
|
||||
///
|
||||
/// let sentence = "We are going to inherit the earth.";
|
||||
/// assert_eq!(sentence.to_shouty_kebab_case(), "WE-ARE-GOING-TO-INHERIT-THE-EARTH");
|
||||
/// ```
|
||||
pub trait ShoutyKebabCase: ToOwned {
|
||||
pub trait ToShoutyKebabCase: ToOwned {
|
||||
/// Convert this type to shouty kebab case.
|
||||
fn to_shouty_kebab_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl ShoutyKebabCase for str {
|
||||
impl ToShoutyKebabCase for str {
|
||||
fn to_shouty_kebab_case(&self) -> Self::Owned {
|
||||
transform(self, uppercase, |s| s.push('-'))
|
||||
}
|
||||
@@ -26,7 +26,7 @@ impl ShoutyKebabCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ShoutyKebabCase;
|
||||
use super::ToShoutyKebabCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
+9
-9
@@ -8,31 +8,31 @@ use crate::{transform, uppercase};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::ShoutySnakeCase;
|
||||
///
|
||||
/// use heck::ToShoutySnakeCase;
|
||||
///
|
||||
/// let sentence = "That world is growing in this minute.";
|
||||
/// assert_eq!(sentence.to_shouty_snake_case(), "THAT_WORLD_IS_GROWING_IN_THIS_MINUTE");
|
||||
/// ```
|
||||
pub trait ShoutySnakeCase: ToOwned {
|
||||
pub trait ToShoutySnakeCase: ToOwned {
|
||||
/// Convert this type to shouty snake case.
|
||||
fn to_shouty_snake_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
/// Oh heck, ShoutySnekCase is an alias for ShoutySnakeCase. See ShoutySnakeCase
|
||||
/// for more documentation.
|
||||
pub trait ShoutySnekCase: ToOwned {
|
||||
/// Oh heck, ToShoutySnekCase is an alias for ToShoutySnakeCase. See
|
||||
/// ToShoutySnakeCase for more documentation.
|
||||
pub trait ToShoutySnekCase: ToOwned {
|
||||
/// CONVERT THIS TYPE TO SNEK CASE.
|
||||
#[allow(non_snake_case)]
|
||||
fn TO_SHOUTY_SNEK_CASE(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl<T: ?Sized + ShoutySnakeCase> ShoutySnekCase for T {
|
||||
impl<T: ?Sized + ToShoutySnakeCase> ToShoutySnekCase for T {
|
||||
fn TO_SHOUTY_SNEK_CASE(&self) -> Self::Owned {
|
||||
self.to_shouty_snake_case()
|
||||
}
|
||||
}
|
||||
|
||||
impl ShoutySnakeCase for str {
|
||||
impl ToShoutySnakeCase for str {
|
||||
fn to_shouty_snake_case(&self) -> Self::Owned {
|
||||
transform(self, uppercase, |s| s.push('_'))
|
||||
}
|
||||
@@ -40,7 +40,7 @@ impl ShoutySnakeCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ShoutySnakeCase;
|
||||
use super::ToShoutySnakeCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
+7
-7
@@ -7,30 +7,30 @@ use crate::{lowercase, transform};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::SnakeCase;
|
||||
/// use heck::ToSnakeCase;
|
||||
///
|
||||
/// let sentence = "We carry a new world here, in our hearts.";
|
||||
/// assert_eq!(sentence.to_snake_case(), "we_carry_a_new_world_here_in_our_hearts");
|
||||
/// ```
|
||||
pub trait SnakeCase: ToOwned {
|
||||
pub trait ToSnakeCase: ToOwned {
|
||||
/// Convert this type to snake case.
|
||||
fn to_snake_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
/// Oh heck, SnekCase is an alias for SnakeCase. See SnakeCase for
|
||||
/// Oh heck, SnekCase is an alias for ToSnakeCase. See ToSnakeCase for
|
||||
/// more documentation.
|
||||
pub trait SnekCase: ToOwned {
|
||||
pub trait ToSnekCase: ToOwned {
|
||||
/// Convert this type to snek case.
|
||||
fn to_snek_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl<T: ?Sized + SnakeCase> SnekCase for T {
|
||||
impl<T: ?Sized + ToSnakeCase> ToSnekCase for T {
|
||||
fn to_snek_case(&self) -> Self::Owned {
|
||||
self.to_snake_case()
|
||||
}
|
||||
}
|
||||
|
||||
impl SnakeCase for str {
|
||||
impl ToSnakeCase for str {
|
||||
fn to_snake_case(&self) -> String {
|
||||
transform(self, lowercase, |s| s.push('_'))
|
||||
}
|
||||
@@ -38,7 +38,7 @@ impl SnakeCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SnakeCase;
|
||||
use super::ToSnakeCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
+4
-4
@@ -8,17 +8,17 @@ use crate::{capitalize, transform};
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use heck::TitleCase;
|
||||
/// use heck::ToTitleCase;
|
||||
///
|
||||
/// let sentence = "We have always lived in slums and holes in the wall.";
|
||||
/// assert_eq!(sentence.to_title_case(), "We Have Always Lived In Slums And Holes In The Wall");
|
||||
/// ```
|
||||
pub trait TitleCase: ToOwned {
|
||||
pub trait ToTitleCase: ToOwned {
|
||||
/// Convert this type to title case.
|
||||
fn to_title_case(&self) -> Self::Owned;
|
||||
}
|
||||
|
||||
impl TitleCase for str {
|
||||
impl ToTitleCase for str {
|
||||
fn to_title_case(&self) -> String {
|
||||
transform(self, capitalize, |s| s.push(' '))
|
||||
}
|
||||
@@ -26,7 +26,7 @@ impl TitleCase for str {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::TitleCase;
|
||||
use super::ToTitleCase;
|
||||
|
||||
macro_rules! t {
|
||||
($t:ident : $s1:expr => $s2:expr) => {
|
||||
|
||||
Reference in New Issue
Block a user