These are chat archives for rust-lang/rust

8th
Oct 2015
panicbit
@panicbit
Oct 08 2015 04:31 UTC
@JohanLarsson It seems to appear in one code sample in the book, but thats about it (https://doc.rust-lang.org/book/error-handling.html#handling-errors-with-option-and-result)
Even the reference doesn't mention the full list of derivable traits. Looks like the knowledge about derivable Traits gets passed on by mouth :P
Johan Larsson
@JohanLarsson
Oct 08 2015 06:20 UTC
Is the irc channel active?
I'm a collector of chats to lurk in :)
Peter Atashian
@retep998
Oct 08 2015 06:21 UTC
yes
IRC is very active
Johan Larsson
@JohanLarsson
Oct 08 2015 06:21 UTC
needs a client right?
Peter Atashian
@retep998
Oct 08 2015 06:21 UTC
Yes, you need some sort of IRC client
although there are web based IRC clients you can use
Johan Larsson
@JohanLarsson
Oct 08 2015 06:21 UTC
ok, chcking i t out
the chat on SO is very nice imo:
been trying to wake it up
it needs a bunch of regs who say something from time to time
Johan Larsson
@JohanLarsson
Oct 08 2015 06:28 UTC
what do you use for UIs when coding in Rust?
Peter Atashian
@retep998
Oct 08 2015 07:14 UTC
I don't!
Because right now there's no Rust libraries directly wrapping native win32 widgets on Windows, and I dislike GTK on Windows
Johan Larsson
@JohanLarsson
Oct 08 2015 07:23 UTC
guess I can write a wrapper function with the cases but nice for tooling to have it like ^
panicbit
@panicbit
Oct 08 2015 07:40 UTC
I don't think that's possible, but a simple macro could cut down the redundancy
panicbit
@panicbit
Oct 08 2015 08:12 UTC
@JohanLarsson: Take a look at what I've come up with :) http://is.gd/6sU3W0
Johan Larsson
@JohanLarsson
Oct 08 2015 08:13 UTC
Nice!
panicbit
@panicbit
Oct 08 2015 08:13 UTC
Macros are pretty mad :D
And safe!
Johan Larsson
@JohanLarsson
Oct 08 2015 08:13 UTC
Can one write custom attributes?
panicbit
@panicbit
Oct 08 2015 08:14 UTC
Like "#[foo]" ?
Or what do you mean exactly?
Johan Larsson
@JohanLarsson
Oct 08 2015 08:14 UTC
I still think there is some sense in #[testcase(777, 777)]
panicbit
@panicbit
Oct 08 2015 08:14 UTC
You should be able to do that but you'd need to write a compiler plugin
Johan Larsson
@JohanLarsson
Oct 08 2015 08:14 UTC
yeah like #[foo]
ok, not for me then :)
panicbit
@panicbit
Oct 08 2015 08:15 UTC
Which also implies that you'd need to use nightly rust
I wish I could get rid of the "=>" but ambiguities force me to place SOMETHING there
You could easily replace it by e.g. a semicolon or whatever suits you
This version of the macro might be better, since it forces you to have at least one test case (and thus the function to be run at least once): http://is.gd/H8rl6C
Johan Larsson
@JohanLarsson
Oct 08 2015 08:22 UTC
yes
I'm gonna try to write my first macro
looks fun
Johan Larsson
@JohanLarsson
Oct 08 2015 09:44 UTC
@panicbit does ^ make any sense?
first macro in any language for me
panicbit
@panicbit
Oct 08 2015 13:03 UTC
Looks fine. (Though, for something simple like this, functions are prefered)
This message was deleted
panicbit
@panicbit
Oct 08 2015 13:09 UTC
On the other hand, typing out the full return type for such a function can be annoying, so using a macro instead is fine too I guess.
Johan Larsson
@JohanLarsson
Oct 08 2015 13:10 UTC
it does not work for static either
time well spent writing it any way
panicbit
@panicbit
Oct 08 2015 13:26 UTC
@JohanLarsson Thanks for bringing up that the Rust book was missing a mention of #[derive()]. I added something about it a few hours ago and it got accepted :). You can read it here if you like.
Johan Larsson
@JohanLarsson
Oct 08 2015 13:47 UTC
@panicbit looks perfect!
Did not know that deriving only works for a limited set
panicbit
@panicbit
Oct 08 2015 14:53 UTC
@JohanLarrson actually that's kind of a lie. You can extend this set with custom derives (like the serde crate does) but that requires nightly rust.
Johan Larsson
@JohanLarsson
Oct 08 2015 20:04 UTC
This message was deleted
think the sample code is broken here
oh, nvm, intentional
Johan Larsson
@JohanLarsson
Oct 08 2015 22:36 UTC
why is impl better than writing methods oo-style?
Peter Atashian
@retep998
Oct 08 2015 22:52 UTC
Because Rust does not have inheritance in the way OOP languages do, adding methods to a type does not affect the layout of the type
Methods can be freely added to or removed from a type without affecting its ABI since it doesn't have a vtable
It also goes well with traits, which can be used to add methods to a type at any time
So it more consistent to always have separate impl blocks
panicbit
@panicbit
Oct 08 2015 22:54 UTC
Also you can implement multiple Traits without worrying about diamond-shaped inheritance.
Peter Atashian
@retep998
Oct 08 2015 22:55 UTC
Look at me, look back at my hand, I'm on a horse, this C++ inheritance is now diamonds
Johan Larsson
@JohanLarsson
Oct 08 2015 22:59 UTC
ok +1 for consistency
I'm an oo-tard, think it is nice to have stuff in the type and be able to collapse the text in the editor.
Inheritance is a smell :)