Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the amount of llvm IR generated #1903

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 26 additions & 15 deletions rusoto/core/src/proto/xml/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use xml;
use xml::reader::{EventReader, Events, ParserConfig, XmlEvent};
use xml::writer::EventWriter;

use crate::{error::RusotoError, request::HttpResponse};
use crate::{request::HttpResponse, HttpDispatchError, RusotoError};

/// generic Error for XML parsing
#[derive(Debug)]
Expand Down Expand Up @@ -121,10 +121,7 @@ pub fn characters<T: Peek + Next>(stack: &mut T) -> Result<String, XmlParseError
}
}
match stack.next() {
Some(Ok(XmlEvent::Characters(data))) |
Some(Ok(XmlEvent::CData(data))) => {
Ok(data)
},
Some(Ok(XmlEvent::Characters(data))) | Some(Ok(XmlEvent::CData(data))) => Ok(data),
_ => Err(XmlParseError::new("Expected characters")),
}
}
Expand Down Expand Up @@ -258,25 +255,39 @@ where
Ok(obj)
}

pub async fn parse_response<T, E>(
pub enum XmlResponseError {
HttpDispatch(HttpDispatchError),
Parse(XmlParseError),
}

impl<E> From<XmlResponseError> for RusotoError<E> {
fn from(err: XmlResponseError) -> Self {
match err {
XmlResponseError::HttpDispatch(err) => RusotoError::HttpDispatch(err),
XmlResponseError::Parse(err) => RusotoError::from(err),
}
}
}

pub async fn parse_response(
response: &mut HttpResponse,
deserialize: fn(&str, &mut XmlResponse<'_>) -> Result<T, XmlParseError>,
) -> Result<T, RusotoError<E>>
where
T: Default,
{
let xml_response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
deserialize: &mut (dyn FnMut(&str, &mut XmlResponse<'_>) -> Result<(), XmlParseError> + Send),
) -> Result<(), XmlResponseError> {
let xml_response = response
.buffer()
.await
.map_err(XmlResponseError::HttpDispatch)?;
if xml_response.body.is_empty() {
Ok(T::default())
Ok(())
} else {
let reader = EventReader::new_with_config(
xml_response.body.as_ref(),
ParserConfig::new().trim_whitespace(false),
);
let mut stack = XmlResponse::new(reader.into_iter().peekable());
let _start_document = stack.next();
let actual_tag_name = peek_at_name(&mut stack)?;
Ok(deserialize(&actual_tag_name, &mut stack)?)
let actual_tag_name = peek_at_name(&mut stack).map_err(XmlResponseError::Parse)?;
Ok(deserialize(&actual_tag_name, &mut stack).map_err(XmlResponseError::Parse)?)
}
}

Expand Down