@@ -684,7 +684,7 @@ pub struct StructCode {
684
684
struct_name_code : Ident ,
685
685
default_code : TokenStream ,
686
686
props : Vec < StructPropCode > ,
687
- continuable : TokenStream ,
687
+ continuable : Option < ContinuableCode > ,
688
688
implement_default : bool ,
689
689
new_fn_params : Vec < TokenStream > ,
690
690
new_fn_body : TokenStream ,
@@ -912,17 +912,69 @@ fn create_struct(
912
912
913
913
let doc_comment = DocCommentCode :: from ( & schema. schema . common . description ) ;
914
914
915
- let mut continuable = quote ! { } ;
916
- if let Some ( pageable) = pageable {
917
- if let Some ( name) = & pageable. next_link_name {
918
- let field_name = name. to_snake_case_ident ( ) ?;
915
+ let continuable = ContinuableCode :: from_pageable ( struct_name_code. clone ( ) , pageable, field_names) ?;
916
+
917
+ Ok ( StructCode {
918
+ doc_comment,
919
+ struct_name_code,
920
+ default_code,
921
+ props,
922
+ continuable,
923
+ implement_default : schema. implement_default ( ) ,
924
+ new_fn_params,
925
+ new_fn_body,
926
+ mod_code,
927
+ ns,
928
+ } )
929
+ }
930
+
931
+ pub struct ContinuableCode {
932
+ pub struct_name : Ident ,
933
+ pub field_name : Option < Ident > ,
934
+ pub is_required : Option < bool > ,
935
+ }
936
+
937
+ impl ContinuableCode {
938
+ pub fn new ( struct_name : Ident , field_name : Option < Ident > , is_required : Option < bool > ) -> Self {
939
+ Self {
940
+ struct_name,
941
+ field_name,
942
+ is_required,
943
+ }
944
+ }
945
+
946
+ pub fn from_pageable ( struct_name : Ident , pageable : Option < & MsPageable > , field_names : HashMap < String , bool > ) -> Result < Option < Self > > {
947
+ if let Some ( pageable) = pageable {
948
+ let field_name = if let Some ( name) = & pageable. next_link_name {
949
+ let field_name = name. to_snake_case_ident ( ) ?;
950
+ Some ( field_name)
951
+ } else {
952
+ None
953
+ } ;
954
+ let is_required = field_name. as_ref ( ) . and_then ( |field_name| field_names. get ( & format ! ( "{field_name}" ) ) ) ;
955
+ Ok ( Some ( Self :: new ( struct_name, field_name, is_required. cloned ( ) ) ) )
956
+ } else {
957
+ Ok ( None )
958
+ }
959
+ }
960
+ }
961
+
962
+ impl ToTokens for ContinuableCode {
963
+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
964
+ let Self {
965
+ struct_name,
966
+ field_name,
967
+ is_required,
968
+ } = self ;
969
+
970
+ if let Some ( field_name) = field_name {
919
971
// when there are multiple responses, we only add the Continuable
920
972
// for the cases that have the field we care about.
921
- // println!("checking {} {} {}", struct_name_code, field_name, field_names.contains(&format!("{}", field_name)) );
922
- if let Some ( is_required) = field_names . get ( & format ! ( "{field_name}" ) ) {
973
+ // println!("checking {} {} {}", struct_name_code, field_name, is_required );
974
+ if let Some ( is_required) = is_required {
923
975
if * is_required {
924
- continuable = quote ! {
925
- impl azure_core:: Continuable for #struct_name_code {
976
+ tokens . extend ( quote ! {
977
+ impl azure_core:: Continuable for #struct_name {
926
978
type Continuation = String ;
927
979
fn continuation( & self ) -> Option <Self :: Continuation > {
928
980
if self . #field_name. is_empty( ) {
@@ -932,60 +984,47 @@ fn create_struct(
932
984
}
933
985
}
934
986
}
935
- } ;
987
+ } ) ;
936
988
} else {
937
- continuable = quote ! {
938
- impl azure_core:: Continuable for #struct_name_code {
989
+ tokens . extend ( quote ! {
990
+ impl azure_core:: Continuable for #struct_name {
939
991
type Continuation = String ;
940
992
fn continuation( & self ) -> Option <Self :: Continuation > {
941
993
self . #field_name. clone( ) . filter( |value| !value. is_empty( ) )
942
994
}
943
995
}
944
- } ;
996
+ } ) ;
945
997
}
946
998
} else {
947
999
// In a number of cases, such as USqlAssemblyList used in
948
1000
// datalake-analytics, the next link name is provided, but the
949
1001
// field doesn't exist in the response schema. Handle that by
950
1002
// adding a Continuable that always returns None.
951
- continuable = quote ! {
952
- impl azure_core:: Continuable for #struct_name_code {
1003
+ tokens . extend ( quote ! {
1004
+ impl azure_core:: Continuable for #struct_name {
953
1005
type Continuation = String ;
954
1006
fn continuation( & self ) -> Option <Self :: Continuation > {
955
1007
None
956
1008
}
957
1009
}
958
- } ;
1010
+ } ) ;
959
1011
}
960
1012
} else {
961
1013
// In a number of cases, such as DimensionsListResult used in
962
1014
// costmanagement, the next link name is null, and it's not provided
963
1015
// via a header or sometimes used in other responses.
964
1016
//
965
1017
// Handle that by // adding a Continuable that always returns None.
966
- continuable = quote ! {
967
- impl azure_core:: Continuable for #struct_name_code {
1018
+ tokens . extend ( quote ! {
1019
+ impl azure_core:: Continuable for #struct_name {
968
1020
type Continuation = String ;
969
1021
fn continuation( & self ) -> Option <Self :: Continuation > {
970
1022
None
971
1023
}
972
1024
}
973
- } ;
1025
+ } ) ;
974
1026
}
975
1027
}
976
-
977
- Ok ( StructCode {
978
- doc_comment,
979
- struct_name_code,
980
- default_code,
981
- props,
982
- continuable,
983
- implement_default : schema. implement_default ( ) ,
984
- new_fn_params,
985
- new_fn_body,
986
- mod_code,
987
- ns,
988
- } )
989
1028
}
990
1029
991
1030
pub struct StructPropCode {
0 commit comments