diff --git a/thrift/annotation/rust.thrift b/thrift/annotation/rust.thrift index 5d4e7eacbae..e22294010d7 100644 --- a/thrift/annotation/rust.thrift +++ b/thrift/annotation/rust.thrift @@ -80,6 +80,7 @@ struct Exhaustive { @scope.Struct @scope.Typedef +@scope.Union struct Ord { // # `rust.Ord` // diff --git a/thrift/compiler/test/fixtures/adapter/out/hack/gen-hack/rust_types.php b/thrift/compiler/test/fixtures/adapter/out/hack/gen-hack/rust_types.php index d7a26108054..4f9b8611e17 100644 --- a/thrift/compiler/test/fixtures/adapter/out/hack/gen-hack/rust_types.php +++ b/thrift/compiler/test/fixtures/adapter/out/hack/gen-hack/rust_types.php @@ -616,6 +616,10 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot shape( ) ), + '\facebook\thrift\annotation\Union' => \facebook\thrift\annotation\Union::fromShape( + shape( + ) + ), ], 'fields' => dict[ ], diff --git a/thrift/compiler/test/fixtures/adapter/out/json/gen-json/rust.json b/thrift/compiler/test/fixtures/adapter/out/json/gen-json/rust.json index fd6fcc7f910..f96fc45855c 100644 --- a/thrift/compiler/test/fixtures/adapter/out/json/gen-json/rust.json +++ b/thrift/compiler/test/fixtures/adapter/out/json/gen-json/rust.json @@ -142,13 +142,13 @@ "column" : 1 }, "end" : { - "line" : 87, + "line" : 88, "column" : 2 } } }, "NewType" : { - "lineno" : 89, + "lineno" : 90, "is_exception" : false, "is_union" : false, "fields" : { @@ -156,17 +156,17 @@ }, "source_range" : { "begin" : { - "line" : 89, + "line" : 90, "column" : 1 }, "end" : { - "line" : 108, + "line" : 109, "column" : 2 } } }, "Type" : { - "lineno" : 110, + "lineno" : 111, "is_exception" : false, "is_union" : false, "fields" : { @@ -176,11 +176,11 @@ "required" : true, "source_range" : { "begin" : { - "line" : 264, + "line" : 265, "column" : 3 }, "end" : { - "line" : 264, + "line" : 265, "column" : 18 } } @@ -188,17 +188,17 @@ }, "source_range" : { "begin" : { - "line" : 110, + "line" : 111, "column" : 1 }, "end" : { - "line" : 265, + "line" : 266, "column" : 2 } } }, "Serde" : { - "lineno" : 271, + "lineno" : 272, "is_exception" : false, "is_union" : false, "fields" : { @@ -208,11 +208,11 @@ "required" : true, "source_range" : { "begin" : { - "line" : 273, + "line" : 274, "column" : 3 }, "end" : { - "line" : 273, + "line" : 274, "column" : 19 } } @@ -220,17 +220,17 @@ }, "source_range" : { "begin" : { - "line" : 271, + "line" : 272, "column" : 1 }, "end" : { - "line" : 274, + "line" : 275, "column" : 2 } } }, "Mod" : { - "lineno" : 280, + "lineno" : 281, "is_exception" : false, "is_union" : false, "fields" : { @@ -240,11 +240,11 @@ "required" : true, "source_range" : { "begin" : { - "line" : 282, + "line" : 283, "column" : 3 }, "end" : { - "line" : 282, + "line" : 283, "column" : 18 } } @@ -252,17 +252,17 @@ }, "source_range" : { "begin" : { - "line" : 280, + "line" : 281, "column" : 1 }, "end" : { - "line" : 283, + "line" : 284, "column" : 2 } } }, "Adapter" : { - "lineno" : 285, + "lineno" : 286, "is_exception" : false, "is_union" : false, "fields" : { @@ -272,11 +272,11 @@ "required" : true, "source_range" : { "begin" : { - "line" : 330, + "line" : 331, "column" : 3 }, "end" : { - "line" : 330, + "line" : 331, "column" : 18 } } @@ -284,17 +284,17 @@ }, "source_range" : { "begin" : { - "line" : 285, + "line" : 286, "column" : 1 }, "end" : { - "line" : 331, + "line" : 332, "column" : 2 } } }, "Derive" : { - "lineno" : 333, + "lineno" : 334, "is_exception" : false, "is_union" : false, "fields" : { @@ -304,11 +304,11 @@ "required" : true, "source_range" : { "begin" : { - "line" : 356, + "line" : 357, "column" : 3 }, "end" : { - "line" : 356, + "line" : 357, "column" : 27 } } @@ -316,17 +316,17 @@ }, "source_range" : { "begin" : { - "line" : 333, + "line" : 334, "column" : 1 }, "end" : { - "line" : 357, + "line" : 358, "column" : 2 } } }, "ServiceExn" : { - "lineno" : 359, + "lineno" : 360, "is_exception" : false, "is_union" : false, "fields" : { @@ -336,11 +336,11 @@ "required" : true, "source_range" : { "begin" : { - "line" : 410, + "line" : 411, "column" : 3 }, "end" : { - "line" : 410, + "line" : 411, "column" : 37 } } @@ -348,11 +348,11 @@ }, "source_range" : { "begin" : { - "line" : 359, + "line" : 360, "column" : 1 }, "end" : { - "line" : 411, + "line" : 412, "column" : 2 } } diff --git a/thrift/compiler/test/fixtures/hack_service/out/hack_module2_with_patch/gen-hack/rust_types.php b/thrift/compiler/test/fixtures/hack_service/out/hack_module2_with_patch/gen-hack/rust_types.php index 564354820d3..a76c086b438 100644 --- a/thrift/compiler/test/fixtures/hack_service/out/hack_module2_with_patch/gen-hack/rust_types.php +++ b/thrift/compiler/test/fixtures/hack_service/out/hack_module2_with_patch/gen-hack/rust_types.php @@ -488,6 +488,10 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot shape( ) ), + '\facebook\thrift\annotation\Union' => \facebook\thrift\annotation\Union::fromShape( + shape( + ) + ), ], 'fields' => dict[ ], diff --git a/thrift/compiler/test/fixtures/rust-annotations/out/rust/gen-rust/types.rs b/thrift/compiler/test/fixtures/rust-annotations/out/rust/gen-rust/types.rs index 9ecd1230293..0717a19d2a1 100644 --- a/thrift/compiler/test/fixtures/rust-annotations/out/rust/gen-rust/types.rs +++ b/thrift/compiler/test/fixtures/rust-annotations/out/rust/gen-rust/types.rs @@ -170,6 +170,7 @@ pub struct U10 { pub enum U11 { string(::std::string::String), integer(::std::primitive::i32), + btreeset(::std::collections::BTreeSet), UnknownField(::std::primitive::i32), } @@ -2110,6 +2111,11 @@ where ::fbthrift::Serialize::write(inner, p); p.write_field_end(); } + Self::btreeset(inner) => { + p.write_field_begin("btreeset", ::fbthrift::TType::Set, 3); + ::fbthrift::Serialize::write(inner, p); + p.write_field_end(); + } Self::UnknownField(_) => {} } p.write_field_stop(); @@ -2124,6 +2130,7 @@ where #[inline] fn read(p: &mut P) -> ::anyhow::Result { static FIELDS: &[::fbthrift::Field] = &[ + ::fbthrift::Field::new("btreeset", ::fbthrift::TType::Set, 3), ::fbthrift::Field::new("integer", ::fbthrift::TType::I32, 2), ::fbthrift::Field::new("str", ::fbthrift::TType::String, 1), ]; @@ -2142,6 +2149,10 @@ where once = true; alt = ::std::option::Option::Some(Self::integer(::fbthrift::Deserialize::read(p)?)); } + (::fbthrift::TType::Set, 3, false) => { + once = true; + alt = ::std::option::Option::Some(Self::btreeset(::fbthrift::Deserialize::read(p)?)); + } (fty, _, false) => p.skip(fty)?, (badty, badid, true) => return ::std::result::Result::Err(::std::convert::From::from(::fbthrift::ProtocolError::UnwantedExtraUnionField( "T11".to_string(), @@ -2162,6 +2173,7 @@ impl U11 { match self { Self::string(_) => ::std::option::Option::Some(("string", "str")), Self::integer(_) => ::std::option::Option::Some(("integer", "integer")), + Self::btreeset(_) => ::std::option::Option::Some(("btreeset", "btreeset")), Self::UnknownField(_) => ::std::option::Option::None, } } @@ -2182,6 +2194,15 @@ impl ::fbthrift::metadata::ThriftAnnotations for U11 { return r.take(); } + if type_id == ::std::any::TypeId::of::() { + let mut tmp = ::std::option::Option::Some(rust__types::Ord { + ..::std::default::Default::default() + }); + let r: &mut dyn ::std::any::Any = &mut tmp; + let r: &mut ::std::option::Option = r.downcast_mut().unwrap(); + return r.take(); + } + ::std::option::Option::None } @@ -2205,6 +2226,8 @@ impl ::fbthrift::metadata::ThriftAnnotations for U11 { }, 2 => { }, + 3 => { + }, _ => {} } diff --git a/thrift/compiler/test/fixtures/rust-annotations/src/module.thrift b/thrift/compiler/test/fixtures/rust-annotations/src/module.thrift index f8c5f9fc9d8..4f8b5ad7dd6 100644 --- a/thrift/compiler/test/fixtures/rust-annotations/src/module.thrift +++ b/thrift/compiler/test/fixtures/rust-annotations/src/module.thrift @@ -136,10 +136,12 @@ struct T10 { typedef i64 t_t1 @rust.Name{name = "U11"} +@rust.Ord union T11 { @rust.Name{name = "string"} 1: string str; 2: i32 integer; + 3: set btreeset; } // --