pub(crate) trait WriteThriftField {
// Required method
fn write_thrift_field<W: Write>(
&self,
writer: &mut ThriftCompactOutputProtocol<W>,
field_id: i16,
last_field_id: i16,
) -> Result<i16>;
}
Expand description
Trait implemented by objects that are fields of Thrift structs.
For example, given the Thrift struct definition
ⓘ
struct MyStruct {
1: required i32 field1
2: optional bool field2
3: optional OtherStruct field3
}
which becomes in Rust
struct MyStruct {
field1: i32,
field2: Option<bool>,
field3: Option<OtherStruct>,
}
the impl of WriteThrift
for MyStruct
will use the WriteThriftField
impls for i32
,
bool
, and OtherStruct
.
ⓘ
impl WriteThrift for MyStruct {
fn write_thrift<W: Write>(&self, writer: &mut ThriftCompactOutputProtocol<W>) -> Result<()> {
let mut last_field_id = 0i16;
last_field_id = self.field1.write_thrift_field(writer, 1, last_field_id)?;
if self.field2.is_some() {
// if field2 is `None` then this assignment won't happen and last_field_id will remain
// `1` when writing `field3`
last_field_id = self.field2.write_thrift_field(writer, 2, last_field_id)?;
}
if self.field3.is_some() {
// no need to assign last_field_id since this is the final field.
self.field3.write_thrift_field(writer, 3, last_field_id)?;
}
writer.write_struct_end()
}
}
Required Methods§
Sourcefn write_thrift_field<W: Write>(
&self,
writer: &mut ThriftCompactOutputProtocol<W>,
field_id: i16,
last_field_id: i16,
) -> Result<i16>
fn write_thrift_field<W: Write>( &self, writer: &mut ThriftCompactOutputProtocol<W>, field_id: i16, last_field_id: i16, ) -> Result<i16>
Used to write struct fields (which may be primitive or IDL defined types). This will
write the field marker for the given field_id
, using last_field_id
to compute the
field delta used by the Thrift compact protocol. On success this will return field_id
to be used in chaining.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.