gpt4 book ai didi

string - 使用 `pop3::POP3Stream::connect` 连接到给定 `host` 的运行时?

转载 作者:行者123 更新时间:2023-11-29 08:08:02 24 4
gpt4 key购买 nike

<分区>

我正在尝试读取用户的输入,然后将其用作 POP3 库的 URL。将我得到的 String 转换为字符串切片时,它的生命周期不够长,无法使用。这对我来说很奇怪,原因有二:

  1. 因为所有使用 POP3 对象的东西都在同一个 block 中,所以 str 切片的生命周期应该是整个 block 的生命周期,这将涵盖所有内容

  2. 我几乎尝试了所有我能想到的不同代码配置,但都无济于事,每次我都会遇到同样的错误。

extern crate pop3;
extern crate smtp;
extern crate openssl;
extern crate libc;

use openssl::ssl::{SslContext, SslMethod};
use pop3::POP3Stream;
use pop3::POP3Result::{POP3Stat, POP3List, POP3Message};

mod readline;
use readline::*;

fn main() {
let place = match readline("URL: ") { // Problem line
Some(input) => { // Problem line
let place: &'static str = &input[..]; // Problem line
let mut email_socket = match POP3Stream::connect(place, 995, Some(SslContext::new(SslMethod::Sslv23).unwrap())) { // Problem line
Ok(s) => s,
Err(e) => panic!("{}", e)
};

match readline("Username: ") {
Some(username) => {
match readline("Password: ") {
Some(password) => { email_socket.login(&*username, &*password); },
None => println!("Please enter a password.")
}
},
None => println!("Please enter a username.")
};

let stat = email_socket.stat();
match stat {
POP3Stat {num_email,
mailbox_size} => println!("num_email: {}, mailbox_size:{}", num_email, mailbox_size),
e => println!("There was an error signing into your server."),
}

let list_all = email_socket.list(None);
match list_all {
POP3List {emails_metadata} => {
for i in emails_metadata.iter() {
println!("message_id: {}, message_size: {}", i.message_id, i.message_size);
}
},
_ => println!("There was an error listing your messages."),
}

let message_25 = email_socket.retr(25);
match message_25 {
POP3Message{raw} => {
for i in raw.iter() {
println!("{}", i);
}
},
_ => println!("There was an error getting your 25th message."),
}

email_socket.quit();
},
None => { println!("Please enter a URL for your server."); }
};
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com