Rewrite deprecated features, such as try!

As taken from
https://github.com/Byron/google-apis-rs/pull/247
This commit is contained in:
Sebastian Thiel
2020-01-18 14:46:53 +08:00
parent a0e0312f69
commit 65b8f0063d
3 changed files with 29 additions and 29 deletions

View File

@@ -493,7 +493,7 @@ match result {
use std::io::{Read, Seek};
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match ${delegate} {
let mut dlg: &mut dyn Delegate = match ${delegate} {
Some(d) => d,
None => &mut dd
};
@@ -722,9 +722,9 @@ else {
mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone())
.add_part(&mut reader, size, reader_mime_type.clone());
let mime_type = mp_reader.mime_type();
(&mut mp_reader as &mut io::Read, ContentType(mime_type))
(&mut mp_reader as &mut dyn io::Read, ContentType(mime_type))
},
_ => (&mut request_value_reader as &mut io::Read, ContentType(json_mime_type.clone())),
_ => (&mut request_value_reader as &mut dyn io::Read, ContentType(json_mime_type.clone())),
};
% endif
let mut client = &mut *self.hub.client.borrow_mut();

View File

@@ -641,8 +641,8 @@ def build_all_params(c, m):
params.insert(0, schema_to_required_property(request_value, REQUEST_VALUE_PROPERTY_NAME))
# add the delegate. It's a type parameter, which has to remain in sync with the type-parameters we actually build.
dp = type(m)({ 'name': DELEGATE_PROPERTY_NAME,
TREF: "&'a mut %s" % DELEGATE_TYPE,
'input_type': "&'a mut %s" % DELEGATE_TYPE,
TREF: "&'a mut dyn %s" % DELEGATE_TYPE,
'input_type': "&'a mut dyn %s" % DELEGATE_TYPE,
'clone_value': '{}',
'skip_example' : True,
'priority': 0,
@@ -855,10 +855,10 @@ def to_extern_crate_name(crate_name):
def docs_rs_url(base_url, crate_name, version):
return base_url + '/' + crate_name + '/' + version
def crate_name(name, version, make):
return library_to_crate_name(library_name(name, version), make.target_suffix)
def gen_crate_dir(name, version, ti):
return to_extern_crate_name(library_to_crate_name(library_name(name, version), ti.target_suffix))

View File

@@ -161,7 +161,7 @@ pub trait Delegate {
/// impending failure.
/// The given Error provides information about why the token couldn't be acquired in the
/// first place
fn token(&mut self, err: &error::Error) -> Option<oauth2::Token> {
fn token(&mut self, err: &dyn error::Error) -> Option<oauth2::Token> {
let _ = err;
None
}
@@ -272,7 +272,7 @@ pub enum Error {
MissingAPIKey,
/// We required a Token, but didn't get one from the Authenticator
MissingToken(Box<error::Error>),
MissingToken(Box<dyn error::Error>),
/// The delgate instructed to cancel the operation
Cancelled,
@@ -301,16 +301,16 @@ impl Display for Error {
writeln!(f, "It is used as there are no Scopes defined for this method.")
},
Error::BadRequest(ref err) => {
try!(writeln!(f, "Bad Request ({}): {}", err.error.code, err.error.message));
writeln!(f, "Bad Request ({}): {}", err.error.code, err.error.message)?;
for err in err.error.errors.iter() {
try!(writeln!(f, " {}: {}, {}{}",
err.domain,
err.message,
err.reason,
match &err.location {
&Some(ref loc) => format!("@{}", loc),
&None => String::new(),
}));
writeln!(f, " {}: {}, {}{}",
err.domain,
err.message,
err.reason,
match &err.location {
&Some(ref loc) => format!("@{}", loc),
&None => String::new(),
})?;
}
Ok(())
},
@@ -337,10 +337,10 @@ impl error::Error for Error {
}
}
fn cause(&self) -> Option<&error::Error> {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Error::HttpError(ref err) => err.cause(),
Error::JsonDecodeError(_, ref err) => err.cause(),
Error::HttpError(ref err) => err.source(),
Error::JsonDecodeError(_, ref err) => err.source(),
_ => None
}
}
@@ -363,8 +363,8 @@ const BOUNDARY: &'static str = "MDuXWGyeE33QFXGchb2VFWc4Z7945d";
/// to google APIs, and might not be a fully-featured implementation.
#[derive(Default)]
pub struct MultiPartReader<'a> {
raw_parts: Vec<(Headers, &'a mut Read)>,
current_part: Option<(Cursor<Vec<u8>>, &'a mut Read)>,
raw_parts: Vec<(Headers, &'a mut dyn Read)>,
current_part: Option<(Cursor<Vec<u8>>, &'a mut dyn Read)>,
last_part_boundary: Option<Cursor<Vec<u8>>>,
}
@@ -386,7 +386,7 @@ impl<'a> MultiPartReader<'a> {
/// `size` - the amount of bytes provided by the reader. It will be put onto the header as
/// content-size.
/// `mime` - It will be put onto the content type
pub fn add_part(&mut self, reader: &'a mut Read, size: u64, mime_type: Mime) -> &mut MultiPartReader<'a> {
pub fn add_part(&mut self, reader: &'a mut dyn Read, size: u64, mime_type: Mime) -> &mut MultiPartReader<'a> {
let mut headers = Headers::new();
headers.set(ContentType(mime_type));
headers.set(ContentLength(size));
@@ -567,10 +567,10 @@ impl Header for ContentRange {
impl HeaderFormat for ContentRange {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(fmt.write_str("bytes "));
fmt.write_str("bytes ")?;
match self.range {
Some(ref c) => try!(c.fmt(fmt)),
None => try!(fmt.write_str("*"))
Some(ref c) => c.fmt(fmt)?,
None => fmt.write_str("*")?
}
(write!(fmt, "/{}", self.total_length)).ok();
Ok(())
@@ -611,13 +611,13 @@ impl HeaderFormat for RangeResponseHeader {
/// A utility type to perform a resumable upload from start to end.
pub struct ResumableUploadHelper<'a, A: 'a> {
pub client: &'a mut hyper::client::Client,
pub delegate: &'a mut Delegate,
pub delegate: &'a mut dyn Delegate,
pub start_at: Option<u64>,
pub auth: &'a mut A,
pub user_agent: &'a str,
pub auth_header: Authorization<Bearer>,
pub url: &'a str,
pub reader: &'a mut ReadSeek,
pub reader: &'a mut dyn ReadSeek,
pub media_type: Mime,
pub content_length: u64
}