mirror of
https://github.com/minio/minio-rs.git
synced 2026-01-22 23:52:07 +08:00
Fix build
This commit is contained in:
parent
d91cdcf02c
commit
21f4de0540
33
src/minio/types.rs
Normal file
33
src/minio/types.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use bytes::Bytes;
|
||||||
|
use hyper::{body::Body, Response};
|
||||||
|
use std::string;
|
||||||
|
use xml;
|
||||||
|
|
||||||
|
pub struct Region(String);
|
||||||
|
|
||||||
|
impl Region {
|
||||||
|
pub fn new(s: &str) -> Region {
|
||||||
|
Region(s.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn empty() -> Region {
|
||||||
|
Region::new("")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_string(&self) -> String {
|
||||||
|
self.0.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Err {
|
||||||
|
InvalidUrl(String),
|
||||||
|
InvalidEnv(String),
|
||||||
|
HttpErr(http::Error),
|
||||||
|
HyperErr(hyper::Error),
|
||||||
|
FailStatusCodeErr(hyper::StatusCode, Bytes),
|
||||||
|
Utf8DecodingErr(string::FromUtf8Error),
|
||||||
|
XmlParseErr(xml::reader::Error),
|
||||||
|
UnexpectedEOF(String),
|
||||||
|
RawSvcErr(hyper::StatusCode, Response<Body>),
|
||||||
|
}
|
||||||
16
src/minio/xml.rs
Normal file
16
src/minio/xml.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use crate::minio::types::{Err, Region};
|
||||||
|
use bytes::Bytes;
|
||||||
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
|
|
||||||
|
pub fn parse_bucket_location(b: Bytes) -> Result<Region, Err> {
|
||||||
|
let mut reader = EventReader::new(b.as_ref());
|
||||||
|
loop {
|
||||||
|
let event = reader.next();
|
||||||
|
match event {
|
||||||
|
Err(err) => return Err(Err::XmlParseErr(err)),
|
||||||
|
Ok(XmlEvent::EndDocument) => return Err(Err::UnexpectedEOF("xml parsing".to_string())),
|
||||||
|
Ok(XmlEvent::Characters(s)) => return Ok(Region::new(&s)),
|
||||||
|
_ => continue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user