liveBook · Manning

Bit field

As explained in Refactoring to Rust

A bitfield is a structure field occupying a specified number of individual bits rather than a whole storage unit.

A bit field stores a field in a specified number of individual bits instead of a whole storage unit. In Rust FFI, bindgen generates accessor functions because Rust does not natively support bit fields. section 4.6

NGINX buffer flags

The C ngx_buf_t structure declares memory, last_buf, and last_in_chain as one-bit fields. Generated setters such as set_last_buf(1), set_memory(1), and set_last_in_chain(1) configure these flags before sending the response. section 4.6

struct ngx_buf_t {
  ... (some fields omitted)
  unsigned         memory:1;
  unsigned         last_buf:1;
  unsigned         last_in_chain:1;
};

Inspect the compact C declaration that represents three one-bit buffer flags. section 4.6

How Refactoring to Rust covers it

How deep it goes
Defines bit fields and demonstrates generated accessors, stopping short of implementing native Rust bit-field support.
Examples
Demonstrates memory, last_buf, and last_in_chain as one-bit fields on ngx_buf_t.
What you can do after
Operate NGINX bit-field flags through bindgen-generated setter functions.
How it connects
Connects bit fields with C structs, Rust FFI, bindgen, and NGINX response buffers.

Also explained in

Compare how 2 books explain bit field →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.