解决这个特定的移动价值?

时间:2015-07-01 01:53:06

标签: rust

我有一个我正在玩的IRC机器人脚本,我遇到了借用检查器的问题,但我似乎无法解决它:

extern crate irc;

use irc::client::prelude::*;

fn main() {
    let config = Config {
        nickname: Some(format!("DwightSchrute")),
        alt_nicks: Some(vec![format!("bananas"), format!("apples")]),
        server: Some(format!("irc.zerosec.net")),
        channels: Some(vec![format!("#main")]),
        .. Default::default()
    };
    let server = IrcServer::from_config(config.clone()).unwrap();                         //config used
    server.identify().unwrap();
    for message in server.iter() {
            let message = message.unwrap(); // We'll just panic if there's an error.
        print!("{}", message.into_string());
        if &message.command[..] == "PRIVMSG" {
            if let Some(msg) = message.suffix {
                if msg.contains("DwightSchrute") {
                    server.send_privmsg(&message.args[0], "Want some of my beets salad?").unwrap();
                }
                if msg.contains("!quit") {
                    server.send_privmsg(&message.args[0], "Off to the Schrute farm, goodbye intellectual inferiors").unwrap();
                                        server.send(Command::QUIT(None));
                }
                if msg.contains("ACTION yawns") {
                    server.send_action(&(config.channels.unwrap()[0]),"fooood");         //desire to use config again
                }
            }
        }
    }
}

问题在于config变量。

1 个答案:

答案 0 :(得分:1)

他们的IRC有用的生锈社区解释了如何使用.as_ref().unwrap转换Option<T>并为您提供Option<&T>