I’m currently working on an SMTP server library and feel like I’m writing a lot of things like "some string".into_string(). That seems redondant and I find into_string() to be quite long. I tried using box "some string" but that yields a Box<&str>, which is not what I want.
Is there any such thing as str!("some string"), where str! is a macro that basically calls into_string()?
I feel like this would make things a bit more readable. What do you think?
It’s something that pretty easy to do yourself. Thats the great thing about macros and syntax extensions, you can add your own sugar without having to bloat the language or the standard libraries.
My goal isn’t so much to find a macro than it is avoiding .into_string() every single time. Any concise solution is good. I don’t see any function named .to_s() in the docs though. What are you referring to?
Hy, if I am not wrong into_string from StrExt is deprecated and .to_owned() should be preferred (but there is also a IntoString and a ToString trait…). Thought generally having a macro witch just calls a method on the passed value sounds like a bad idea.
But due to the frequent usage of str with to_string, into_string and to_owned I think the existence of a standard macro like owned! is justified maybe even preferable.
Also reading owned!("hallo") pretty clearly says what is does and looks more clear than a lot of .to_owned() calls and is less ambiguous then a str!("halo") macro.