mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
feat(type-params): ground work for upload media
This might mean we need additional type parameters, but I will see how it's going to work out. In theory, we could define a new trait for Seek+Read, but this would mean that we couldn't contain owned streams. For max flexibility, it's better to have additional type parameters and use BorrowMut to allow ownership, and borrow.
This commit is contained in:
@@ -16,10 +16,6 @@ license = "${copyright.license_abbrev}"
|
||||
keywords = ["${name}", ${", ".join(util.estr(cargo.keywords))}]
|
||||
|
||||
[dependencies]
|
||||
# Just to get hyper to work !
|
||||
openssl = "= 0.4.3"
|
||||
# Just to get hyper to work !
|
||||
cookie = "= 0.1.13"
|
||||
hyper = "*"
|
||||
rustc-serialize = "*"
|
||||
yup-oauth2 = "*"
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<%
|
||||
from util import (iter_nested_types, new_context, rust_comment, rust_doc_comment,
|
||||
rust_module_doc_comment, rb_type, hub_type, mangle_ident)
|
||||
nested_schemas = list(iter_nested_types(schemas))
|
||||
<%
|
||||
from util import (iter_nested_types, new_context, rust_comment, rust_doc_comment,
|
||||
rust_module_doc_comment, rb_type, hub_type, mangle_ident, hub_type_params_s)
|
||||
|
||||
c = new_context(resources)
|
||||
|
||||
hub_type = hub_type(canonicalName)
|
||||
|
||||
nested_schemas = list(iter_nested_types(schemas))
|
||||
c = new_context(resources)
|
||||
hub_type = hub_type(canonicalName)
|
||||
ht_params = hub_type_params_s()
|
||||
%>\
|
||||
<%namespace name="lib" file="lib/lib.mako"/>\
|
||||
<%namespace name="util" file="lib/util.mako"/>\
|
||||
@@ -69,20 +68,20 @@ macro_rules! map(
|
||||
<%block filter="rust_doc_comment">\
|
||||
<%lib:hub_usage_example/>\
|
||||
</%block>
|
||||
pub struct ${hub_type}<C, NC, A> {
|
||||
pub struct ${hub_type}${ht_params} {
|
||||
client: RefCell<C>,
|
||||
auth: RefCell<A>,
|
||||
_m: PhantomData<NC>
|
||||
}
|
||||
|
||||
impl<'a, C, NC, A> Hub for ${hub_type}<C, NC, A> {}
|
||||
impl<'a, C, NC, A> Hub for ${hub_type}${ht_params} {}
|
||||
|
||||
impl<'a, C, NC, A> ${hub_type}<C, NC, A>
|
||||
impl<'a, C, NC, A> ${hub_type}${ht_params}
|
||||
where NC: hyper::net::NetworkConnector,
|
||||
C: BorrowMut<hyper::Client<NC>> + 'a,
|
||||
A: oauth2::GetToken {
|
||||
|
||||
pub fn new(client: C, authenticator: A) -> ${hub_type}<C, NC, A> {
|
||||
pub fn new(client: C, authenticator: A) -> ${hub_type}${ht_params} {
|
||||
${hub_type} {
|
||||
client: RefCell::new(client),
|
||||
auth: RefCell::new(authenticator),
|
||||
|
||||
@@ -75,6 +75,12 @@ ${'##'} About parts
|
||||
* Optionals needed for Json, otherwise I'd happily drop them
|
||||
* explain that examples use all response parts, even though they are shown for request values
|
||||
|
||||
${'##'} About builder arguments
|
||||
|
||||
* pods are copy
|
||||
* strings are &str
|
||||
* request values are borrowed
|
||||
|
||||
[builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern
|
||||
[google-go-api]: https://github.com/google/google-api-go-client
|
||||
</%def>
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
split_camelcase_s, property, is_pod_property, TREF, method_io, IO_REQUEST,
|
||||
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)
|
||||
indent_by, to_rust_type, rnd_arg_val_for_type, extract_parts, mb_type_params_s,
|
||||
hub_type_params_s)
|
||||
|
||||
def get_parts(part_prop):
|
||||
if not part_prop:
|
||||
@@ -33,7 +34,8 @@
|
||||
hub_type_name = hub_type(canonicalName)
|
||||
m = c.fqan_map[to_fqan(name, resource, method)]
|
||||
# an identifier for a property. We prefix them to prevent clashes with the setters
|
||||
ThisType = mb_type(resource, method) + "<'a, C, NC, A>"
|
||||
mb_tparams = mb_type_params_s(m)
|
||||
ThisType = mb_type(resource, method) + mb_tparams
|
||||
|
||||
params, request_value = build_all_params(schemas, c, m, IO_REQUEST, REQUEST_VALUE_PROPERTY_NAME)
|
||||
part_prop = None
|
||||
@@ -68,7 +70,7 @@ pub struct ${ThisType}
|
||||
C: 'a,
|
||||
A: 'a, {
|
||||
|
||||
hub: &'a ${hub_type_name}<C, NC, A>,
|
||||
hub: &'a ${hub_type_name}${hub_type_params_s()},
|
||||
## PROPERTIES ###############
|
||||
% for p in params:
|
||||
${property(p.name)}:\
|
||||
@@ -80,9 +82,9 @@ pub struct ${ThisType}
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl<'a, C, NC, A> MethodBuilder for ${ThisType} {}
|
||||
impl${mb_tparams} MethodBuilder for ${ThisType} {}
|
||||
|
||||
impl<'a, C, NC, A> ${ThisType} {
|
||||
impl${mb_tparams} ${ThisType} {
|
||||
|
||||
${self._action_fn(resource, method, params, request_value, parts)}\
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<%!
|
||||
from util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment,
|
||||
from util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment,
|
||||
rb_type, singular, hub_type, mangle_ident, mb_type, method_params, property,
|
||||
to_fqan, indent_all_but_first_by, schema_markers,
|
||||
activity_input_type, TREF, method_io, IO_REQUEST, schema_to_required_property,
|
||||
rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME,
|
||||
build_all_params)
|
||||
build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s)
|
||||
%>\
|
||||
<%namespace name="util" file="util.mako"/>\
|
||||
<%namespace name="lib" file="lib.mako"/>\
|
||||
@@ -14,8 +14,9 @@
|
||||
###############################################################################################
|
||||
<%def name="new(resource, c)">\
|
||||
<%
|
||||
hub_type_name = hub_type(canonicalName)
|
||||
ThisType = rb_type(resource) + "<'a, C, NC, A>"
|
||||
hub_type_name = hub_type(canonicalName)
|
||||
rb_params = rb_type_params_s()
|
||||
ThisType = rb_type(resource) + rb_params
|
||||
%>\
|
||||
/// A builder providing access to all methods supported on *${singular(resource)}* resources.
|
||||
/// It is not used directly, but through the `${hub_type_name}` hub.
|
||||
@@ -41,48 +42,50 @@ pub struct ${ThisType}
|
||||
C: 'a,
|
||||
A: 'a, {
|
||||
|
||||
hub: &'a ${hub_type_name}<C, NC, A>
|
||||
hub: &'a ${hub_type_name}${hub_type_params_s()}
|
||||
}
|
||||
|
||||
impl<'a, C, NC, A> ResourceMethodsBuilder for ${ThisType} {}
|
||||
impl${rb_params} ResourceMethodsBuilder for ${ThisType} {}
|
||||
|
||||
## Builder Creators Methods ####################
|
||||
impl<'a, C, NC, A> ${ThisType} {
|
||||
% for a in c.rta_map[resource]:
|
||||
impl${rb_params} ${ThisType} {
|
||||
% for a in c.rta_map[resource]:
|
||||
<%
|
||||
m = c.fqan_map[to_fqan(name, resource, a)]
|
||||
RType = mb_type(resource, a)
|
||||
m = c.fqan_map[to_fqan(name, resource, a)]
|
||||
RType = mb_type(resource, a)
|
||||
|
||||
# skip part if we have a request resource. Only resources can have parts
|
||||
# that we can easily deduce
|
||||
params, request_value = build_all_params(schemas, c, m, IO_REQUEST, REQUEST_VALUE_PROPERTY_NAME)
|
||||
required_props, optional_props, part_prop = organize_params(params, request_value)
|
||||
# skip part if we have a request resource. Only resources can have parts
|
||||
# that we can easily deduce
|
||||
params, request_value = build_all_params(schemas, c, m, IO_REQUEST, REQUEST_VALUE_PROPERTY_NAME)
|
||||
required_props, optional_props, part_prop = organize_params(params, request_value)
|
||||
|
||||
method_args = ''
|
||||
if required_props:
|
||||
method_args = ', ' + ', '.join('%s: %s' % (mangle_ident(p.name), activity_input_type(p)) for p in required_props)
|
||||
method_args = ''
|
||||
if required_props:
|
||||
method_args = ', ' + ', '.join('%s: %s' % (mangle_ident(p.name), activity_input_type(p)) for p in required_props)
|
||||
|
||||
mb_tparams = mb_type_params_s(m)
|
||||
%>\
|
||||
|
||||
% if 'description' in m:
|
||||
/// Create a builder to help you perform the following task:
|
||||
///
|
||||
${m.description | rust_doc_comment, indent_all_but_first_by(1)}
|
||||
% endif
|
||||
pub fn ${mangle_ident(a)}(&self${method_args}) -> ${RType}<'a, C, NC, A> {
|
||||
${RType} {
|
||||
hub: self.hub,
|
||||
% for p in required_props:
|
||||
${property(p.name)}: ${rust_copy_value_s(mangle_ident(p.name), activity_input_type(p), p)},
|
||||
% endfor
|
||||
## auto-generate parts from request resources
|
||||
% if part_prop and request_value:
|
||||
${property(part_prop.name)}: ${mangle_ident(REQUEST_VALUE_PROPERTY_NAME)}.to_parts(),
|
||||
% endif
|
||||
% for p in optional_props:
|
||||
${property(p.name)}: Default::default(),
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
% endfor ## for each activity
|
||||
|
||||
% if 'description' in m:
|
||||
/// Create a builder to help you perform the following task:
|
||||
///
|
||||
${m.description | rust_doc_comment, indent_all_but_first_by(1)}
|
||||
% endif
|
||||
pub fn ${mangle_ident(a)}(&self${method_args}) -> ${RType}${mb_tparams} {
|
||||
${RType} {
|
||||
hub: self.hub,
|
||||
% for p in required_props:
|
||||
${property(p.name)}: ${rust_copy_value_s(mangle_ident(p.name), activity_input_type(p), p)},
|
||||
% endfor
|
||||
## auto-generate parts from request resources
|
||||
% if part_prop and request_value:
|
||||
${property(part_prop.name)}: ${mangle_ident(REQUEST_VALUE_PROPERTY_NAME)}.to_parts(),
|
||||
% endif
|
||||
% for p in optional_props:
|
||||
${property(p.name)}: Default::default(),
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
% endfor ## for each activity
|
||||
}
|
||||
</%def>
|
||||
@@ -40,6 +40,8 @@ REQUEST_PRIORITY = 100
|
||||
REQUEST_MARKER = 'RequestValue'
|
||||
REQUEST_VALUE_PROPERTY_NAME = 'request'
|
||||
|
||||
HUB_TYPE_PARAMETERS = ('C', 'NC', 'A')
|
||||
|
||||
# ==============================================================================
|
||||
## @name Filters
|
||||
# ------------------------------------------------------------------------------
|
||||
@@ -478,6 +480,21 @@ def library_name(name, version):
|
||||
def rb_type(r):
|
||||
return "%sMethodsBuilder" % singular(canonical_type_name(r))
|
||||
|
||||
def _to_type_params_s(p):
|
||||
return '<%s>' % ', '.join(p)
|
||||
|
||||
# return type parameters of a the hub, ready for use in Rust code
|
||||
def hub_type_params_s():
|
||||
return _to_type_params_s(HUB_TYPE_PARAMETERS)
|
||||
|
||||
# type parameters for a resource builder - keeps hub as borrow
|
||||
def rb_type_params_s():
|
||||
return _to_type_params_s(("'a", ) + HUB_TYPE_PARAMETERS)
|
||||
|
||||
# type params for the given method builder, as string suitable for Rust code
|
||||
def mb_type_params_s(m):
|
||||
return _to_type_params_s(("'a", ) + HUB_TYPE_PARAMETERS)
|
||||
|
||||
# return type name for a method on the given resource
|
||||
def mb_type(r, m):
|
||||
return "%s%sMethodBuilder" % (singular(canonical_type_name(r)), m.capitalize())
|
||||
|
||||
Reference in New Issue
Block a user