blob: b5704aada9a938bd04556a66925e9f7cb5a48938 [file] [log] [blame]
{{/*
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
*/}}
{{- define "TableDeclaration" }}
{{- range .DocComments }}
///{{ . }}
{{- end }}
{{ .Derives }}
pub struct {{ .Name }} {
{{- range .Members }}
{{- range .DocComments }}
///{{ . }}
{{- end }}
pub {{ .Name }}: Option<{{ .Type.Owned }}>,
{{- end }}
#[deprecated = "Use `..{{ .Name }}::EMPTY` to construct and `..` to match."]
#[doc(hidden)]
pub __non_exhaustive: (),
}
impl {{ .Name }} {
{{- /* TODO(fxbug.dev/102876): Remove the EMPTY const. */}}
/// An empty table with every field set to `None`.
#[allow(deprecated)]
pub const EMPTY: Self = Self {
{{- range .Members }}
{{ .Name }}: None,
{{- end }}
__non_exhaustive: (),
};
}
impl std::default::Default for {{ .Name }} {
fn default() -> Self {
Self::EMPTY
}
}
{{- if .IsResourceType }}
impl fidl::encoding::Standalone for {{ .Name }} {}
{{- else }}
impl fidl::encoding::Persistable for {{ .Name }} {}
{{- end }}
fidl_table! {
name: {{ .Name }},
{{- if .IsResourceType }}
resource: true,
{{- end }}
members: [
{{- range .Members }}
{{ .Name }} {
ty: {{ .Type.Fidl }},
{{- if .Type.IsResourceType }}
resource: true,
{{- end }}
ordinal: {{ .Ordinal }},
},
{{- end }}
],
}
{{- end }}