blob: a6e4d512a8771579efbc0096fda070853878679f [file] [log] [blame] [edit]
{{/*
// Copyright 2019 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 "BitsDeclaration" -}}
bitflags! {
{{- range .DocComments }}
///{{ . }}
{{- end }}
#[derive(Default)]
pub struct {{ .Name }}: {{ .UnderlyingType }} {
{{- range .Members }}
{{- range .DocComments }}
///{{ . }}
{{- end }}
const {{ .Name }} = {{ .Value }};
{{- end }}
}
}
impl {{ .Name }} {
{{- if .IsStrict }}
#[deprecated = "Strict bits should not use `has_unknown_bits`"]
#[inline(always)]
pub fn has_unknown_bits(&self) -> bool {
false
}
#[deprecated = "Strict bits should not use `get_unknown_bits`"]
#[inline(always)]
pub fn get_unknown_bits(&self) -> {{ .UnderlyingType }} {
0
}
{{- else }}
#[inline(always)]
pub fn from_bits_allow_unknown(bits: {{ .UnderlyingType }}) -> Self {
{{- /* TODO(fxbug.dev/124335): Use `from_bits_retain` instead. */}}
unsafe { Self::from_bits_unchecked(bits) }
}
#[inline(always)]
pub fn has_unknown_bits(&self) -> bool {
self.get_unknown_bits() != 0
}
#[inline(always)]
pub fn get_unknown_bits(&self) -> {{ .UnderlyingType }} {
self.bits & !Self::all().bits
}
{{- end }}
}
fidl_bits! {
name: {{ .Name }},
prim_ty: {{ .UnderlyingType }},
{{- if .IsStrict }}
strict: true,
{{- else }}
flexible: true,
{{- end }}
}
{{ end }}