liveBook · Manning

Callback

As explained in Refactoring to Rust

A callback function is a function supplied to another operation so that it can be invoked when a specified event or computation completes.

A callback is a function passed to another operation so it can be invoked when an event or computation completes. In NGINX request handling, Rust supplies read_body_handler to run after the request body is read. section 4.4

Passing a request-body callback

The handler starts asynchronous body reading by passing Some(read_body_handler) to ngx_http_read_client_request_body. The callback receives the request pointer, checks for null, converts the body, and reports parsing errors.

A callback crossing the Rust–C FFI boundary requires:

  • An extern "C" function signature for C calling conventions. section 4.4

How Refactoring to Rust covers it

How deep it goes
Explains callback registration, C-compatible signatures, raw pointers, null checks, and body parsing, but not general callback abstractions.
Examples
Demonstrates read_body_handler passed to NGINX and used to inspect a request body.
What it assumes
Assumes basic Rust and C interoperability while showing the required function-pointer, calling-convention, and raw-pointer details.
What you can do after
Build callbacks for NGINX FFI integrations and validate raw request pointers before processing data.
How it connects
Connects callbacks with foreign-function interfaces, function pointers, unsafe Rust, raw pointers, and asynchronous request handling.

Also explained in

Compare how 18 books explain callback →

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.