Macro rubedo::s

source ·
macro_rules! s {
    ($s:expr) => { ... };
    () => { ... };
}
Expand description

Converts a str string literal to an owned String.

This macro provides syntactic sugar to convert static str instances to Strings - this saves having to do "foo".to_owned() or String::from("foo").

It will also convert any other type that implements the ToString trait to a String. This is perhaps not as useful as the str conversion, but it does provide a consistent interface for converting to Strings. When converting from other types it is likely best to use the standard conversion functions directly, to avoid confusion, and so the recommendation is to only use this macro as shorthand for converting str instances.

The inspiration for this macro comes from the velcro crate, which provides a range of macros for creating collections, building on the built-in vec! macro.

Examples

use rubedo::s;
 
assert_eq!(s!("foo"), "foo");
assert_eq!(s!("foo"), "foo".to_owned());
assert_eq!(s!("foo"), "foo".to_string());
assert_eq!(s!("foo"), String::from("foo"));

See Also