This crate provides the extension_fn macro for extending types with extension functions.
For example there is a countnumbers extension function for str: ```rust /// Replacement for: /// Sealed is internal trait that used to provide only one implementation of trait and nobody outside module can implement this /// pub trait CountNumbers: Sealed { /// fn countnumbers(&self) -> u32; /// } /// impl CountNumbers for str { /// fn count_numbers(&self) -> u32 { ... } /// }
pub fn countnumbers(&self) -> u32 {
self.chars().fold(0, |count, char| {
if char.isnumeric() {
count + 1
} else {
count
}
})
}
You can extend using async functions by adding async-trait to your dependencies:
toml
[dependencies]
async-trait = "*"
Also you can extend types that matching trait bound:
rust
pub fn count_numbers(&self) { ... } ```