Take Login ext_uris values as a slice to allow caller to avoid allocation

In some cases the caller might be able to use a const slice for this.
This commit is contained in:
Dirkjan Ochtman 2022-01-20 09:04:14 +01:00 committed by masalachai
parent 58b72f9b0c
commit 9acd9eac29
2 changed files with 4 additions and 4 deletions

View File

@ -27,8 +27,8 @@ pub struct Login<'a> {
} }
impl<'a> Login<'a> { impl<'a> Login<'a> {
pub fn new(username: &'a str, password: &'a str, ext_uris: Option<Vec<&'a str>>) -> Self { pub fn new(username: &'a str, password: &'a str, ext_uris: Option<&'_ [&'a str]>) -> Self {
let ext_uris = ext_uris.map(|uris| uris.into_iter().map(|u| u.into()).collect()); let ext_uris = ext_uris.map(|uris| uris.iter().map(|&u| u.into()).collect());
Self { Self {
username: username.into(), username: username.into(),
@ -72,7 +72,7 @@ mod tests {
#[test] #[test]
fn command() { fn command() {
let ext_uris = Some(vec!["http://schema.ispapi.net/epp/xml/keyvalue-1.0"]); let ext_uris = Some(&["http://schema.ispapi.net/epp/xml/keyvalue-1.0"][..]);
let xml = get_xml("request/login.xml").unwrap(); let xml = get_xml("request/login.xml").unwrap();
let object = Login::new("username", "password", ext_uris); let object = Login::new("username", "password", ext_uris);

View File

@ -92,7 +92,7 @@ async fn client() {
&Login::new( &Login::new(
"username", "username",
"password", "password",
Some(vec!["http://schema.ispapi.net/epp/xml/keyvalue-1.0"]), Some(&["http://schema.ispapi.net/epp/xml/keyvalue-1.0"]),
), ),
CLTRID, CLTRID,
) )