Simplify type system to leverage 'Sync' types

These are generally available now that we use hyper's async
APIs along with the most recent yup-hypermock.
This commit is contained in:
Sebastian Thiel
2021-04-14 09:52:27 +08:00
parent fe6ccfed3f
commit 9c339da955
5 changed files with 13 additions and 24 deletions

View File

@@ -5,7 +5,7 @@
<%namespace name="schema" file="lib/schema.mako"/>\
<%
from util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
rb_type, hub_type, mangle_ident, hub_type_params_s, hub_type_bounds,
rb_type, hub_type, mangle_ident, hub_type_params_s,
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
UNUSED_TYPE_MARKER, schema_markers)
@@ -17,7 +17,6 @@
%>\
use std::collections::HashMap;
use std::cell::RefCell;
use std::borrow::BorrowMut;
use std::default::Default;
use std::collections::BTreeMap;
use serde_json as json;
@@ -49,7 +48,7 @@ ${lib.scope_enum()}
${lib.hub_usage_example(c)}\
</%block>
pub struct ${hub_type}${ht_params} {
client: RefCell<C>,
client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>,
auth: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>,
_user_agent: String,
_base_url: String,
@@ -58,12 +57,11 @@ pub struct ${hub_type}${ht_params} {
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> client::Hub for ${hub_type}${ht_params} {}
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
where ${', '.join(hub_type_bounds())} {
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params} {
pub fn new(client: C, authenticator: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>) -> ${hub_type}${ht_params} {
pub fn new(client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>, authenticator: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>) -> ${hub_type}${ht_params} {
${hub_type} {
client: RefCell::new(client),
client,
auth: authenticator,
_user_agent: "${default_user_agent}".to_string(),
_base_url: "${baseUrl}".to_string(),

View File

@@ -26,7 +26,7 @@ ${lib.docs(c)}
<%namespace name="schema" file="lib/schema.mako"/>\
<%
from util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
rb_type, hub_type, mangle_ident, hub_type_params_s, hub_type_bounds,
rb_type, hub_type, mangle_ident, hub_type_params_s,
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
UNUSED_TYPE_MARKER, schema_markers)

View File

@@ -6,7 +6,7 @@
schema_to_required_property, rust_copy_value_s, is_required_property,
hide_rust_doc_test, build_all_params, REQUEST_VALUE_PROPERTY_NAME, organize_params,
indent_by, to_rust_type, rnd_arg_val_for_type, extract_parts, mb_type_params_s,
hub_type_params_s, method_media_params, enclose_in, mb_type_bounds, method_response,
hub_type_params_s, method_media_params, enclose_in, method_response,
CALL_BUILDER_MARKERT_TRAIT, pass_through, markdown_rust_block, parts_from_params,
DELEGATE_PROPERTY_NAME, struct_type_bounds_s, scope_url_to_variant,
re_find_replacements, ADD_PARAM_FN, ADD_PARAM_MEDIA_EXAMPLE, upload_action_fn, METHODS_RESOURCE,
@@ -132,7 +132,7 @@ pub struct ${ThisType}
impl${mb_tparams} ${CALL_BUILDER_MARKERT_TRAIT} for ${ThisType} {}
impl${mb_tparams} ${ThisType} where ${', '.join(mb_type_bounds())} {
impl${mb_tparams} ${ThisType} {
% if api.get('no_upload_prefix') is not None and ThisType.startswith(api.no_upload_prefix):
${self._action_fn(c, resource, method, m, params, request_value, parts, doit_without_upload = True)}\
% endif
@@ -744,7 +744,7 @@ else {
_ => (&mut request_value_reader as &mut dyn io::Read, (CONTENT_TYPE, json_mime_type.to_string())),
};
% endif
let mut client = &mut *self.hub.client.borrow_mut();
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(${method_name_to_variant(m.httpMethod)}).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone())\
@@ -792,7 +792,7 @@ else {
% endif
;
client.borrow_mut().request(request.unwrap()).await
client.request(request.unwrap()).await
</%block>\
% if resumable_media_param:
@@ -833,7 +833,6 @@ else {
% if resumable_media_param:
if protocol == "${resumable_media_param.protocol}" {
${READER_SEEK | indent_all_but_first_by(6)}
let mut client = &mut *self.hub.client.borrow_mut();
let upload_result = {
let url_str = &res.headers().get("Location").expect("LOCATION header is part of protocol").to_str().unwrap();
if upload_url_from_server {
@@ -841,7 +840,7 @@ else {
}
client::ResumableUploadHelper {
client: &mut client.borrow_mut(),
client: &self.hub.client,
delegate: dlg,
start_at: if upload_url_from_server { Some(0) } else { None },
auth: &${auth_call},

View File

@@ -112,7 +112,7 @@ data_unit_multipliers = {
'%': 1,
}
HUB_TYPE_PARAMETERS = ('C',)
HUB_TYPE_PARAMETERS = ()
def items(p):
if isinstance(p, dict):
@@ -899,10 +899,6 @@ def _to_type_params_s(p):
def hub_type_params_s():
return _to_type_params_s(HUB_TYPE_PARAMETERS)
# return a list of where statements to server as bounds for the hub.
def hub_type_bounds():
return ['C: BorrowMut<hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>>']
# Returns True if this API has particular authentication scopes to choose from
def supports_scopes(auth):
return bool(auth) and bool(auth.oauth2)
@@ -922,10 +918,6 @@ def method_default_scope(m):
# end try to find read-only default scope
return default_scope
# return list of type bounds required by method builder
def mb_type_bounds():
return hub_type_bounds()
_rb_type_params = ("'a", ) + HUB_TYPE_PARAMETERS

View File

@@ -607,7 +607,7 @@ impl 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 client: &'a hyper::client::Client<
hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>,
hyper::body::Body,
>,