@@ -76,7 +76,7 @@ ${m.description | rust_doc_comment}
7676% else :
7777/// A builder for the *${ method} * method supported by a *${ singular(resource)} * resource.
7878% endif
79- /// It is not used directly, but through a `${ rb_type(resource)} `.
79+ /// It is not used directly, but through a `${ rb_type(resource)} ` instance .
8080///
8181% if part_desc:
8282${ part_desc | rust_doc_comment}
@@ -307,7 +307,7 @@ ${capture(util.test_prelude) | hide_filter}\
307307use ${ util.library_name()} ::${ request_value_type} ;
308308% endif
309309% if handle_result:
310- use ${ util.library_name()} ::Result;
310+ use ${ util.library_name()} ::{ Result, Error} ;
311311% endif
312312% if media_params:
313313use std::fs;
@@ -358,15 +358,17 @@ ${'.' + action_name | indent_by(13)}(${action_args});
358358% if handle_result:
359359
360360match result {
361- Result::HttpError(err) => println!("HTTPERROR: {:?}", err),
362- Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
363- Result::MissingToken => println!("OAuth2: Missing Token"),
364- Result::Cancelled => println!("Operation canceled by user"),
365- Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
366- Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
367- Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
368- Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
369- Result::Success(_) => println!("Success (value doesn't print)"),
361+ Err(e) => match e {
362+ Error::HttpError(err) => println!("HTTPERROR: {:?}", err),
363+ Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
364+ Error::MissingToken => println!("OAuth2: Missing Token"),
365+ Error::Cancelled => println!("Operation canceled by user"),
366+ Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
367+ Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
368+ Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
369+ Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
370+ },
371+ Ok(_) => println!("Success (value doesn't print)"),
370372}
371373% endif
372374</%block >
@@ -447,7 +449,7 @@ match result {
447449 if media_params:
448450 max_size = media_params[0 ].max_size
449451 if max_size > 0 :
450- READER_SEEK += " if size > %i {\n\t return Result ::UploadSizeLimitExceeded(size, %i )\n }" % (max_size, max_size)
452+ READER_SEEK += " if size > %i {\n\t return Err(Error ::UploadSizeLimitExceeded(size, %i ) )\n }" % (max_size, max_size)
451453
452454 special_cases = set ()
453455 for possible_url in possible_urls:
@@ -527,7 +529,7 @@ match result {
527529 for &field in [${ ' , ' .join(enclose_in(' "' , reserved_params + [p.name for p in field_params]))} ].iter() {
528530 if ${ paddfields} .contains_key(field) {
529531 ${ delegate_finish} (false);
530- return Result ::FieldClash(field);
532+ return Err(Error ::FieldClash(field) );
531533 }
532534 }
533535 for (name, value) in ${ paddfields} .iter() {
@@ -589,7 +591,7 @@ else {
589591 Some(value) => params.push(("key", value)),
590592 None => {
591593 ${ delegate_finish} (false);
592- return Result ::MissingAPIKey
594+ return Err(Error ::MissingAPIKey)
593595 }
594596 }
595597 % else :
@@ -668,7 +670,7 @@ else {
668670 }
669671 if token.is_none() {
670672 ${ delegate_finish} (false);
671- return Result ::MissingToken
673+ return Err(Error ::MissingToken)
672674 }
673675 let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
674676 access_token: token.unwrap().access_token });
@@ -757,7 +759,7 @@ else {
757759 continue;
758760 }
759761 ${ delegate_finish} (false);
760- return Result ::HttpError(err)
762+ return Err(Error ::HttpError(err) )
761763 }
762764 Ok(mut res) => {
763765 if !res.status.is_success() {
@@ -768,7 +770,7 @@ else {
768770 continue;
769771 }
770772 ${ delegate_finish} (false);
771- return Result ::Failure(res)
773+ return Err(Error ::Failure(res) )
772774 }
773775 % if resumable_media_param:
774776 if protocol == "${ resumable_media_param.protocol} " {
@@ -796,12 +798,12 @@ else {
796798 match upload_result {
797799 None => {
798800 ${ delegate_finish} (false);
799- return Result ::Cancelled
801+ return Err(Error ::Cancelled)
800802 }
801803 Some(Err(err)) => {
802804 ## Do not ask the delgate again, as it was asked by the helper !
803805 ${ delegate_finish} (false);
804- return Result ::HttpError(err)
806+ return Err(Error ::HttpError(err) )
805807 }
806808 ## Now the result contains the actual resource, if any ... it will be
807809 ## decoded next
@@ -810,7 +812,7 @@ else {
810812 if !res.status.is_success() {
811813 ## delegate was called in upload() already - don't tell him again
812814 ${ delegate_finish} (false);
813- return Result ::Failure(res)
815+ return Err(Error ::Failure(res) )
814816 }
815817 }
816818 }
@@ -829,7 +831,7 @@ if enable_resource_parsing \
829831 Ok(decoded) => (res, decoded),
830832 Err(err) => {
831833 dlg.response_json_decode_error(&json_response, &err);
832- return Result ::JsonDecodeError(err);
834+ return Err(Error ::JsonDecodeError(err) );
833835 }
834836 }
835837 }\
@@ -842,7 +844,7 @@ if enable_resource_parsing \
842844 % endif
843845
844846 ${ delegate_finish} (true);
845- return Result::Success (result_value)
847+ return Ok (result_value)
846848 }
847849 }
848850 }
0 commit comments