docs(mbuild): more information, nicer visuals

This commit is contained in:
Sebastian Thiel
2015-03-05 16:21:39 +01:00
parent a3206abc92
commit 4e8872b37a
2 changed files with 507 additions and 622 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -24,9 +24,11 @@
required_props, optional_props, part_prop = organize_params(params, request_value)
is_string_value = lambda v: v.endswith('"')
# to rust value
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(to_rust_type(sn, spn, sp, allow_optionals=False))
rb_name = 'request' # name of request binding
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:
# could also just skip the first element, but ... let's be safe
@@ -39,6 +41,8 @@
required_args.append(v)
# end for each required property
required_args = ', '.join(required_args)
random_value_warning = "Values shown here are random and not representative !"
%>\
% if 'description' in m:
${m.description | rust_doc_comment}
@@ -53,43 +57,47 @@ ${m.description | rust_doc_comment}
///
<%block filter="rust_doc_test_norun, rust_doc_comment">\
${capture(util.test_prelude) | hide_rust_doc_test}\
# use ${util.library_name()}::*;
% if request_value:
# use ${util.library_name()}::${request_value.id};
% endif
<%block filter="rust_test_fn_invisible">\
${capture(lib.test_hub, hub_type_name, comments=False) | hide_rust_doc_test}
% if request_value:
// As the method needs a request, you would usually fill it with the desired information.
// What can actually be filled in depends on the actual call - the following is just a
// random selection of properties ! Values are random and not representative !
// As the method needs a request, you would usually fill it with the desired information
// into the respective structure.
// ${random_value_warning}
let mut ${rb_name}: ${request_value.id} = Default::default();
% for spn, sp in request_value.get('properties', dict()).iteritems():
<%
assignment = rvfrt(spn, sp, request_value.id)
rtn = trv(spn, sp, request_value.id)
assignment = rnd_arg_val_for_type(rtn)
if is_string_value(assignment):
assignment = assignment + '.to_string()'
if assignment.endswith('default()'):
assignment = assignment[1:] # cut & - it's not ok in this case :)!
assignment += '; // is %s' % rtn
else:
assignment = 'Some(%s)' % assignment
assignment = 'Some(%s);' % assignment
%>\
## ${to_rust_type(request_value.id, spn, sp, allow_optionals=False)}
${rb_name}.${mangle_ident(spn)} = ${assignment};
${rb_name}.${mangle_ident(spn)} = ${assignment}
% endfor
% endif
// Even though you wouldn't bind this to a variable, you can configure optional parameters
// by calling the respective setters.
// Values are random and not representative !
let mut mb = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_args})\
// You can configure optional parameters by calling the respective setters at will, and
// execute the final call using `${api.terms.action}()`.
% if optional_props:
// ${random_value_warning}
% endif
let result = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_args})\
% for p in optional_props:
<%block filter="indent_by(8)">\
.${mangle_ident(p.name)}(${rvfrt(p.name, p)})\
</%block>\
% endfor
;
// Finally, execute your call and process the result
mb.${api.terms.action}()
.${api.terms.action}();
// TODO: show how to handle the result !
</%block>
</%block>
pub struct ${ThisType}