{{! Copyright (c) Meta Platforms, Inc. and its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. }} {{^struct:union?}} #[allow(clippy::derivable_impls)] impl ::std::default::Default for self::{{struct:rust_name}} { fn default() -> Self { Self {{>lib/block}}{{! }}{{#struct:fields}} {{field:rust_name}}: {{! }}{{#field:default}}{{! }}{{#field:optional?}}{{! }}{{#program:deprecated_optional_with_default_is_some?}}{{! }}{{#field:has_adapter?}}{{>lib/adapter/qualified}}::from_thrift_default::<{{struct:rust_name}}>({{/field:has_adapter?}}{{! }}{{>lib/fieldvalue}}{{! }}{{#field:has_adapter?}}, {{field:key}}){{/field:has_adapter?}}{{! }}{{/program:deprecated_optional_with_default_is_some?}}{{! }}{{^program:deprecated_optional_with_default_is_some?}}{{! }}::std::option::Option::None{{! }}{{/program:deprecated_optional_with_default_is_some?}}{{! }}{{/field:optional?}}{{! }}{{^field:optional?}}{{! }}{{#field:has_adapter?}}{{>lib/adapter/qualified}}::from_thrift_default::<{{struct:rust_name}}>({{/field:has_adapter?}}{{! }}{{>lib/fieldvalue}}{{! }}{{#field:has_adapter?}}, {{field:key}}){{/field:has_adapter?}}{{! }}{{/field:optional?}}{{! }}{{/field:default}}{{! }}{{^field:default}}{{! }}{{#field:optional?}}{{! }}::std::option::Option::None{{! }}{{/field:optional?}}{{! }}{{^field:optional?}}{{! }}{{#field:has_adapter?}}{{>lib/adapter/qualified}}::from_thrift_default::<{{struct:rust_name}}>({{/field:has_adapter?}}{{! }}::std::default::Default::default(){{! }}{{#field:has_adapter?}}, {{field:key}}){{/field:has_adapter?}}{{! }}{{/field:optional?}}{{! }}{{/field:default}}{{! }},{{! }}{{/struct:fields}} {{>lib/structvalue_epilogue}} } } } impl ::std::fmt::Debug for self::{{struct:rust_name}} { fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { formatter .debug_struct("{{struct:rust_name}}"){{! }}{{#struct:fields}} .field("{{field:rust_name}}", &self.{{field:rust_name}}){{! }}{{/struct:fields}} .finish() } } {{! Avoid needing to raise the recursion_limit for the trait solver to figure out autotrait impls for deeply nested data structures. These unsafe impls are fine because all possible field types we allow (primitives, string, vec, maps, sets) are Send and Sync and Unpin. }} unsafe impl ::std::marker::Send for self::{{struct:rust_name}} {} unsafe impl ::std::marker::Sync for self::{{struct:rust_name}} {} impl ::std::marker::Unpin for self::{{struct:rust_name}} {} impl ::std::panic::RefUnwindSafe for self::{{struct:rust_name}} {} impl ::std::panic::UnwindSafe for self::{{struct:rust_name}} {} impl ::fbthrift::GetTType for self::{{struct:rust_name}} { const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct; } {{!newline}} {{#struct:thrift_uri}} impl ::fbthrift::GetUri for self::{{struct:rust_name}} { fn uri() -> &'static str { "{{struct:thrift_uri}}" } } {{/struct:thrift_uri}} impl
::fbthrift::Serialize
for self::{{struct:rust_name}} where P: ::fbthrift::ProtocolWriter, { fn write(&self, p: &mut P) { p.write_struct_begin("{{struct:name}}");{{! }}{{#struct:fields}}{{! }}{{#field:optional?}} if let ::std::option::Option::Some(some) = &self.{{field:rust_name}} { p.write_field_begin({{! }}"{{field:name}}", {{! }}{{#field:type}}{{>lib/ttype}}{{/field:type}}, {{! }}{{field:key}}{{! }}); {{#field:type}}{{#field:type_annotation?}}{{>lib/annfieldwrite}}{{/field:type_annotation?}}{{^field:type_annotation?}}{{>lib/write}}{{/field:type_annotation?}}{{/field:type}}({{! }}{{#field:has_adapter?}}&{{>lib/adapter/qualified}}::to_thrift_field::<{{struct:rust_name}}>({{/field:has_adapter?}}{{! }}some{{! }}{{#field:has_adapter?}}, {{field:key}}){{/field:has_adapter?}}{{! }}, p); p.write_field_end(); }{{! }}{{/field:optional?}}{{! }}{{^field:optional?}} p.write_field_begin({{! }}"{{field:name}}", {{! }}{{#field:type}}{{>lib/ttype}}{{/field:type}}, {{! }}{{field:key}}{{! }}); {{#field:type}}{{#field:type_annotation?}}{{>lib/annfieldwrite}}{{/field:type_annotation?}}{{^field:type_annotation?}}{{>lib/write}}{{/field:type_annotation?}}{{/field:type}}({{! }}{{#field:has_adapter?}}&{{>lib/adapter/qualified}}::to_thrift_field::<{{struct:rust_name}}>({{/field:has_adapter?}}{{! }}&self.{{field:rust_name}}{{! }}{{#field:has_adapter?}}, {{field:key}}){{/field:has_adapter?}}{{! }}, p); p.write_field_end();{{! }}{{/field:optional?}}{{! }}{{/struct:fields}} p.write_field_stop(); p.write_struct_end(); } } impl
::fbthrift::Deserialize
for self::{{struct:rust_name}}
where
P: ::fbthrift::ProtocolReader,
{
fn read(p: &mut P) -> ::anyhow::Result