Skip to content

Names and imports

helpers4 is one crate with one module per category. A deliberate consequence is that the same function name can exist in several modules when the operation makes sense for different kinds of data: merging them into one generic function would make the types less precise and the behavior harder to predict.

Generated from the documented version, so it always matches it.

ItemModules
parseduration, env

Import through the module path, and do not glob-import a module (use helpers4::string::*;): the next name collision would then be yours to debug.

use helpers4::string::capitalize;

assert_eq!(capitalize("hello"), "Hello");

When you need two helpers with the same name in one file, rename at the import site with as, suffixing the module name so the origin stays visible:

use helpers4::string::truncate as truncate_string;

assert_eq!(truncate_string("A very long title", 10, "..."), "A very ...");

The same applies to a name that also exists in the standard library or in another crate you use.