On 04/23/2013 03:24 PM, Marvin Löbel wrote:
Ever since fail and assert got turned into macros, failing with a string message has become quite line-noisy:

fail!(~"cause")


Personally I think 3 is the easiest to implement option, and nice even without the fmt! optimisation. I already locally implemented the necessary changes that would allow switching to it after an snapshot, but I wanted to ask what others think.


From what you've presented, I like 3.

I agree with this sentiment in general, and agree that all these related string-taking macros, assert, fail, debug, etc. should behave similarly, generally accepting whatever you throw at them. It would be very desirable I think to not duplicate the string in the case where ~str is the only argument. This could probably be done with a trait that converts to ~str by value (so ~str.to_str_by_val() is a no-op).

We have always had this lingering notion that fail *could* accept a dynamically typed twiddle, called `~Any`. If we go this direction of passing everything through `fmt!` then that becomes more complicated.

I think there will be solutions though. In the case where `fail` is passed just one argument it could be interpreted as an instance of some trait, Exceptiony, that can be called to cast the value to `~Any`. When multiple arguments are passed it delegates to fmt.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to