initial commit
This commit is contained in:
commit
d4143caf16
7 changed files with 1706 additions and 0 deletions
24
src/xml.rs
Normal file
24
src/xml.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use rocket::http::Status;
|
||||
use rocket::Request;
|
||||
use rocket::response::Responder;
|
||||
use serde::Serialize;
|
||||
use rocket::response::Result;
|
||||
use log::error;
|
||||
use rocket::response::content::RawXml;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Xml<T>(pub T);
|
||||
|
||||
impl<'r, 'o: 'r, T: Serialize> Responder<'r, 'o> for Xml<T>{
|
||||
fn respond_to(self, request: &'r Request<'_>) -> Result<'o> {
|
||||
match quick_xml::se::to_string(&self.0){
|
||||
Ok(ser) => {
|
||||
RawXml(ser).respond_to(request)
|
||||
},
|
||||
Err(e) => {
|
||||
error!("serialization error: {}", e);
|
||||
Err(Status::InternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue