The compiler doesn't seem to infer that the integer variables are passed as string literals into the concat!
macro, so I found the stringify!
macro that converts these integer variables into string literals, but this looks ugly:
fn date(year: u8, month: u8, day: u8) -> String
{
concat!(stringify!(month), "/",
stringify!(day), "/",
stringify!(year)).to_string()
}
concat!
takes literals and produces a &'static str
at compile time. You should use format!
for this:
fn date(year: u8, month: u8, day: u8) -> String {
format!("{}/{}/{}", month, day, year)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With