use alloc::{
borrow::ToOwned,
string::{String, ToString},
};
usecrate::{capitalize, lowercase, transform};
/// This trait defines a lower camel case conversion. /// /// In lowerCamelCase, word boundaries are indicated by capital letters, /// excepting the first word. /// /// ## Example: /// /// ```rust /// use heck::ToLowerCamelCase; /// /// let sentence = "It is we who built these palaces and cities."; /// assert_eq!(sentence.to_lower_camel_case(), "itIsWeWhoBuiltThesePalacesAndCities"); /// ``` pubtrait ToLowerCamelCase: ToOwned { /// Convert this type to lower camel case. fn to_lower_camel_case(&self) -> Self::Owned;
}
/// This wrapper performs a lower camel case conversion in [`fmt::Display`]. /// /// ## Example: /// /// ``` /// use heck::AsLowerCamelCase; /// /// let sentence = "It is we who built these palaces and cities."; /// assert_eq!(format!("{}", AsLowerCamelCase(sentence)), "itIsWeWhoBuiltThesePalacesAndCities"); /// ``` pubstruct AsLowerCamelCase<T: AsRef<str>>(pub T);
impl<T: AsRef<str>> fmt::Display for AsLowerCamelCase<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { letmut first = true;
transform( self.0.as_ref(),
|s, f| { if first {
first = false;
lowercase(s, f)
} else {
capitalize(s, f)
}
},
|_| Ok(()),
f,
)
}
}
#[cfg(test)] mod tests { usesuper::ToLowerCamelCase;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.