2015-07-01 49 views
0

我有我與玩弄這個IRC bot的劇本,我跑進與借檢查一個問題,但我似乎無法來解決它:解決這個特定的移動值?

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

在他們的IRC樂於助人的防鏽社區介紹瞭如何使用.as_ref().unwrap轉換Option<T>併爲您提供Option<&T>