| ::fidl_next::bitflags::bitflags! { |
| {{ self.doc_string(bits.attributes) -}} |
| #[derive( |
| Clone, |
| Copy, |
| {% if self.emit_debug_impls() -%} |
| Debug, |
| {%- endif %} |
| PartialEq, |
| Eq, |
| Hash, |
| )] |
| pub struct {{ name }}: {{ natural_subtype }} { |
| {% for member in bits.members -%} |
| {{ self.doc_string(member.attributes) -}} |
| const {{ member.name|screaming_snake }} = {{ member.value.value }}; |
| {% endfor %} |
| {%- if !bits.is_strict -%} |
| const _ = !0; |
| {%- endif %} |
| } |
| } |
| |
| impl ::fidl_next::Encodable for {{ name }} { |
| type Encoded = {{ wire_name }}; |
| } |
| |
| unsafe impl<___E> ::fidl_next::Encode<___E> for {{ name }} |
| where |
| ___E: ?Sized, |
| { |
| #[inline] |
| fn encode( |
| self, |
| encoder: &mut ___E, |
| out: &mut ::core::mem::MaybeUninit<Self::Encoded>, |
| ) -> ::core::result::Result<(), ::fidl_next::EncodeError> { |
| ::fidl_next::EncodeRef::encode_ref(&self, encoder, out) |
| } |
| } |
| |
| unsafe impl<___E> ::fidl_next::EncodeRef<___E> for {{ name }} |
| where |
| ___E: ?Sized, |
| { |
| #[inline] |
| fn encode_ref( |
| &self, |
| _: &mut ___E, |
| out: &mut ::core::mem::MaybeUninit<Self::Encoded>, |
| ) -> ::core::result::Result<(), ::fidl_next::EncodeError> { |
| ::fidl_next::munge!(let {{ wire_name }} { value } = out); |
| {% if bits.is_strict %} |
| if ::fidl_next::bitflags::Flags::contains_unknown_bits(self) { |
| return Err(::fidl_next::EncodeError::InvalidStrictBits); |
| } |
| {% endif %} |
| let _ = value.write({{ wire_subtype }}::from(self.bits())); |
| Ok(()) |
| } |
| } |
| |
| impl ::core::convert::From<{{ wire_name }}> for {{ name }} { |
| fn from(wire: {{ wire_name }}) -> Self { |
| Self::from_bits_retain({{ natural_subtype }}::from(wire.value)) |
| } |
| } |
| |
| impl ::fidl_next::FromWire<{{ wire_name }}> for {{ name }} { |
| #[inline] |
| fn from_wire(wire: {{ wire_name }}) -> Self { |
| Self::from(wire) |
| } |
| } |
| |
| impl ::fidl_next::IntoNatural for {{ wire_name }} { |
| type Natural = {{ name }}; |
| } |
| |
| impl ::fidl_next::FromWireRef<{{ wire_name}}> for {{ name }} { |
| #[inline] |
| fn from_wire_ref(wire: &{{ wire_name }}) -> Self { |
| Self::from(*wire) |
| } |
| } |
| |
| /// The wire type corresponding to [`{{ name }}`]. |
| #[derive( |
| Clone, |
| Copy, |
| {% if self.emit_debug_impls() -%} |
| Debug, |
| {%- endif %} |
| )] |
| #[repr(transparent)] |
| pub struct {{ wire_name }} { |
| value: {{ wire_subtype }}, |
| } |
| |
| unsafe impl ::fidl_next::Wire for {{ wire_name }} { |
| type Decoded<'de> = Self; |
| |
| #[inline] |
| fn zero_padding(_: &mut ::core::mem::MaybeUninit<Self>) { |
| // Wire bits have no padding |
| } |
| } |
| |
| unsafe impl<___D> ::fidl_next::Decode<___D> for {{ wire_name }} |
| where |
| ___D: ?Sized, |
| { |
| fn decode( |
| slot: ::fidl_next::Slot<'_, Self>, |
| _: &mut ___D, |
| ) -> ::core::result::Result<(), ::fidl_next::DecodeError> { |
| {% if bits.is_strict %} |
| ::fidl_next::munge!(let Self { value } = slot); |
| let set = {{ natural_subtype }}::from(*value); |
| if set & !{{ name }}::all().bits() != 0 { |
| return Err(::fidl_next::DecodeError::InvalidBits { |
| expected: {{ name }}::all().bits() as usize, |
| actual: set as usize, |
| }); |
| } |
| {% endif %} |
| Ok(()) |
| } |
| } |
| |
| impl ::core::convert::From<{{ name }}> for {{ wire_name }} { |
| fn from(natural: {{ name }}) -> Self { |
| Self { |
| value: {{ wire_subtype }}::from(natural.bits()), |
| } |
| } |
| } |