|
47 | 47 | PART_MARKER_TRAIT = 'Part' |
48 | 48 | NESTED_MARKER_TRAIT = 'NestedType' |
49 | 49 | REQUEST_VALUE_PROPERTY_NAME = 'request' |
| 50 | +DELEGATE_TYPE_PARAM = 'D' |
50 | 51 |
|
51 | 52 | PROTOCOL_TYPE_INFO = { |
52 | 53 | 'simple' : { |
@@ -487,12 +488,23 @@ def method_media_params(m): |
487 | 488 |
|
488 | 489 | return res |
489 | 490 |
|
| 491 | +# Build all parameters used in a given method ! |
490 | 492 | # schemas, context, method(dict), 'request'|'response', request_prop_name -> (params, request_value|None) |
491 | 493 | def build_all_params(schemas, c, m, n, npn): |
492 | 494 | request_value = method_io(schemas, c, m, n) |
493 | 495 | params = method_params(m) |
494 | 496 | if request_value: |
495 | 497 | params.insert(0, schema_to_required_property(request_value, npn)) |
| 498 | + # add the delegate. It's a type parameter, which has to remain in sync with the type-parameters we actually build. |
| 499 | + dp = type(m)({ 'name': 'delegate', |
| 500 | + TREF: DELEGATE_TYPE_PARAM, |
| 501 | + 'priority': 0, |
| 502 | + 'description': |
| 503 | +"""The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong |
| 504 | +while executing the actual API request. |
| 505 | +
|
| 506 | +It should be used to handle progress information, and to implement a certain level of resilience."""}) |
| 507 | + params.append(dp) |
496 | 508 | return params, request_value |
497 | 509 |
|
498 | 510 |
|
@@ -568,13 +580,32 @@ def _to_type_params_s(p): |
568 | 580 | def hub_type_params_s(): |
569 | 581 | return _to_type_params_s(HUB_TYPE_PARAMETERS) |
570 | 582 |
|
| 583 | +# return a list of where statements to server as bounds for the hub. |
| 584 | +def hub_type_bounds(): |
| 585 | + return ['NC: hyper::net::NetworkConnector', |
| 586 | + "C: BorrowMut<hyper::Client<NC>> + 'a", |
| 587 | + 'A: oauth2::GetToken'] |
| 588 | + |
| 589 | +# return list of type bounds required by method builder |
| 590 | +def mb_type_bounds(): |
| 591 | + return hub_type_bounds() + [DELEGATE_TYPE_PARAM + ': Delegate'] |
| 592 | + |
| 593 | +DEFAULT_MB_TYPE_PARAMS = (DELEGATE_TYPE_PARAM, ) |
| 594 | + |
| 595 | +_rb_type_params = ("'a", ) + HUB_TYPE_PARAMETERS |
| 596 | + |
| 597 | + |
571 | 598 | # type parameters for a resource builder - keeps hub as borrow |
572 | | -def rb_type_params_s(): |
573 | | - return _to_type_params_s(("'a", ) + HUB_TYPE_PARAMETERS) |
| 599 | +def rb_type_params_s(resource, c): |
| 600 | + return _to_type_params_s(_rb_type_params) |
574 | 601 |
|
575 | 602 | # type params for the given method builder, as string suitable for Rust code |
576 | 603 | def mb_type_params_s(m): |
577 | | - return _to_type_params_s(("'a", ) + HUB_TYPE_PARAMETERS) |
| 604 | + return _to_type_params_s(_rb_type_params + DEFAULT_MB_TYPE_PARAMS) |
| 605 | + |
| 606 | +# as rb_additional_type_params, but for an individual method, as seen from a resource builder ! |
| 607 | +def mb_additional_type_params(m): |
| 608 | + return DEFAULT_MB_TYPE_PARAMS |
578 | 609 |
|
579 | 610 | # return type name for a method on the given resource |
580 | 611 | def mb_type(r, m): |
|
0 commit comments