mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-24 12:15:55 +01:00
fix(delegate): it now works in every which way
Custom property annotations have been very useful, to steer very special cases. It's also good that now there is enough infrastructure to deal with any amount of additional type parameters.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// DO NOT EDIT
|
||||
use std::marker::MarkerTrait;
|
||||
use std::io::{Read, Seek};
|
||||
use std::borrow::BorrowMut;
|
||||
|
||||
use oauth2;
|
||||
use hyper;
|
||||
@@ -54,7 +53,7 @@ struct JsonServerError {
|
||||
///
|
||||
/// It contains methods to deal with all common issues, as well with the ones related to
|
||||
/// uploading media
|
||||
pub trait Delegate: Clone {
|
||||
pub trait Delegate {
|
||||
|
||||
/// Called whenever there is an HttpError, usually if there are network problems.
|
||||
///
|
||||
@@ -63,3 +62,8 @@ pub trait Delegate: Clone {
|
||||
oauth2::Retry::Abort
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DefaultDelegate;
|
||||
|
||||
impl Delegate for DefaultDelegate {}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@ use std::default::Default;
|
||||
use std::io::{Read, Seek};
|
||||
use std::fs;
|
||||
|
||||
pub use cmn::{Hub, ReadSeek, ResourceMethodsBuilder, MethodBuilder, Resource, Part, ResponseResult, RequestValue, NestedType, Delegate};
|
||||
pub use cmn::{Hub, ReadSeek, ResourceMethodsBuilder, MethodBuilder, Resource, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate};
|
||||
|
||||
|
||||
// ##############
|
||||
|
||||
@@ -188,6 +188,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
|
||||
trv = lambda spn, sp, sn=None: to_rust_type(sn, spn, sp, allow_optionals=False)
|
||||
# rvfrt = random value for rust type
|
||||
rvfrt = lambda spn, sp, sn=None: rnd_arg_val_for_type(trv(spn, sp, sn))
|
||||
|
||||
rb_name = 'req' # name of request binding
|
||||
required_args = request_value and ['&' + rb_name] or []
|
||||
for p in required_props:
|
||||
@@ -251,6 +252,9 @@ ${rb_name}.${mangle_ident(spn)} = ${assignment}
|
||||
% endif
|
||||
let result = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_args})\
|
||||
% for p in optional_props:
|
||||
% if p.get('skip_example', False):
|
||||
<% continue %>
|
||||
% endif
|
||||
|
||||
<%block filter="indent_by(13)">\
|
||||
.${mangle_ident(p.name)}(${rvfrt(p.name, p)})\
|
||||
|
||||
@@ -42,12 +42,12 @@ DEL_METHOD = 'delete'
|
||||
NESTED_TYPE_MARKER = 'is_nested'
|
||||
SPACES_PER_TAB = 4
|
||||
|
||||
DELEGATE_TYPE = 'Delegate'
|
||||
REQUEST_PRIORITY = 100
|
||||
REQUEST_MARKER_TRAIT = 'RequestValue'
|
||||
PART_MARKER_TRAIT = 'Part'
|
||||
NESTED_MARKER_TRAIT = 'NestedType'
|
||||
REQUEST_VALUE_PROPERTY_NAME = 'request'
|
||||
DELEGATE_TYPE_PARAM = 'D'
|
||||
|
||||
PROTOCOL_TYPE_INFO = {
|
||||
'simple' : {
|
||||
@@ -303,6 +303,8 @@ def is_nested_type(s):
|
||||
# convert a rust-type to something that would be taken as input of a function
|
||||
# even though our storage type is different
|
||||
def activity_input_type(p):
|
||||
if 'input_type' in p:
|
||||
return p.input_type
|
||||
n = activity_rust_type(p, allow_optionals=False)
|
||||
if n == 'String':
|
||||
n = 'str'
|
||||
@@ -426,6 +428,8 @@ def method_io(schemas, c, m, type, marker=None):
|
||||
|
||||
# return string like 'n.clone()', but depending on the type name of tn (e.g. &str -> n.to_string())
|
||||
def rust_copy_value_s(n, tn, p):
|
||||
if 'clone_value' in p:
|
||||
return p.clone_value.format(n)
|
||||
nc = n + '.clone()'
|
||||
if tn == '&str':
|
||||
nc = n + '.to_string()'
|
||||
@@ -497,7 +501,10 @@ def build_all_params(schemas, c, m, n, npn):
|
||||
params.insert(0, schema_to_required_property(request_value, npn))
|
||||
# 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',
|
||||
TREF: DELEGATE_TYPE_PARAM,
|
||||
TREF: "&'a mut %s" % DELEGATE_TYPE,
|
||||
'input_type': "&'a mut %s" % DELEGATE_TYPE,
|
||||
'clone_value': '{}',
|
||||
'skip_example' : True,
|
||||
'priority': 0,
|
||||
'description':
|
||||
"""The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||||
@@ -588,9 +595,7 @@ def hub_type_bounds():
|
||||
|
||||
# return list of type bounds required by method builder
|
||||
def mb_type_bounds():
|
||||
return hub_type_bounds() + [DELEGATE_TYPE_PARAM + ': Delegate']
|
||||
|
||||
DEFAULT_MB_TYPE_PARAMS = (DELEGATE_TYPE_PARAM, )
|
||||
return hub_type_bounds()
|
||||
|
||||
_rb_type_params = ("'a", ) + HUB_TYPE_PARAMETERS
|
||||
|
||||
@@ -601,11 +606,11 @@ def rb_type_params_s(resource, c):
|
||||
|
||||
# type params for the given method builder, as string suitable for Rust code
|
||||
def mb_type_params_s(m):
|
||||
return _to_type_params_s(_rb_type_params + DEFAULT_MB_TYPE_PARAMS)
|
||||
return _to_type_params_s(_rb_type_params)
|
||||
|
||||
# as rb_additional_type_params, but for an individual method, as seen from a resource builder !
|
||||
def mb_additional_type_params(m):
|
||||
return DEFAULT_MB_TYPE_PARAMS
|
||||
return []
|
||||
|
||||
# return type name for a method on the given resource
|
||||
def mb_type(r, m):
|
||||
|
||||
@@ -93,7 +93,7 @@ mod tests {
|
||||
<MemoryStorage as Default>::default(), None);
|
||||
let mut hub = YouTube::new(hyper::Client::new(), auth);
|
||||
let result = hub.channel_sections().insert()
|
||||
.delegate(&mut <DefaultDelegate as Default>::default())
|
||||
.delegate(&mut DefaultDelegate)
|
||||
.doit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user