aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
531 stars 97 forks source link

[API Improvement] Implement ToMessage for Command and Message and use ToMessage in Connection #11

Closed sbstp closed 9 years ago

sbstp commented 9 years ago

Hello! I wanted to simplify the API of the send method to be simpler. I didn't like having to use to_message after creating a command, so now the library does it. I was inspired by ToSocketAddr which allows you to convert a bunch of things into a SocketAddr. Essentially, send now takes a ToMessage trait, and anything can implement that and be converted to a Message. The old API isn't broken as long as ToMessage is imported (althought to_message is used twice).

// new way
c.send(NICK("bob"));
// old way, still works
c.send(NICK("bob").to_message());

Also sorry about the diff, my editor removed trailing white space here and there.

aatxe commented 9 years ago

I'm curious. Under what context are you using Connection directly?

sbstp commented 9 years ago

As a client to connect to a remote irc server.

let c = Connection::connect("irc.freenode.net", 6667).unwrap();
c.send(USER("...", "8", "..."));
aatxe commented 9 years ago

What specifically do you gain from it versus just using IrcServer?

sbstp commented 9 years ago

I want to write a bot, can the IrcServer connect to say freenode and listen to events?

aatxe commented 9 years ago

Yes, IrcServer is an abstraction over Connection. There's a number of examples in the examples folder. There's also a simple shell in the README. These changes look good, and I like them. I was just curious as to what you were using Connection for directly.

sbstp commented 9 years ago

Alright thanks. It could also be possible to implement ToMessage for &str and be able to send raw command strings to be parsed.

aatxe commented 9 years ago

A bug was stopping CLAHub from properly notifying me about contributor license agreements. Can you please sign this, @SBSTP? https://www.clahub.com/agreements/aatxe/irc

sbstp commented 9 years ago

Hey. Although I'm not very fond of CLAs I signed it. One thing that's really nice about free software is that you never have to "agree to terms of service". I know that this is different and that you're protecting your project, but I think that it's less than an ideal way of dealing with the issue. I don't like agreeing to terms on the Internet.

aatxe commented 9 years ago

Strictly speaking, it's not really a CLA. It's just a public domain declaration. It doesn't just protect this project, it protects everyone who uses it. Unfortunately, public domain laws are somewhat weird, and it's difficult for collaborative projects to exist in the public domain. This is the best solution I have to do it. Though, I suppose a statement in the PR would be equally sufficient.

sbstp commented 9 years ago

Ok, fair enough. I understand the the bot is a nice commodity to have.