tree: 4eb76c2aed425ceda74a4cdea984e555ca1ddc7f [path history] [tgz]
  1. child/
  2. parent/
  3. BUILD.gn
  4. README.md
  5. realm_test.rs
examples/drivers/transport/zircon/rust_next/README.md

Zircon Transport Rust Example

Reviewed on: 2025-07-29

This example demonstrates a parent driver serving the fuchsia.hardware.i2c FIDL protocol over zircon transport and a child driver that connects to the protocol to interact with the parent driver, with both drivers written in rust and using the new rust wire bindings.

Building

To include the driver to your build, append --with //examples/drivers:drivers to your fx set command. For example:

$ fx set core.x64 --with //examples/drivers:drivers
$ fx build

Running

Register the parent driver by running this command

$ ffx driver register fuchsia-pkg://fuchsia.com/zircon_transport_rust_next#meta/zircon_transport_parent.cm

Register the child driver by running this command

$ ffx driver register fuchsia-pkg://fuchsia.com/zircon_transport_rust_next#meta/zircon_transport_child.cm

Verify that both drivers show up in this command

ffx driver list

Add a test node that binds to the parent driver:

$ ffx driver test-node add zircon_transport_rust_next_parent gizmo.example.TEST_NODE_ID=zircon_transport_rust_next_parent

Run the following command to verify that the driver is bound to the node:

$ ffx driver list-devices -v transport_rust

You should see something like this:

Name     : zircon_transport_rust_next_parent
Moniker  : dev.zircon_transport_rust_next_parent
Driver   : fuchsia-pkg://fuchsia.com/zircon_transport_rust_next#meta/zircon_transport_parent.cm
1 Properties
[ 1/  1] : Key "gizmo.example.TEST_NODE_ID"   Value "zircon_transport_rust_next_parent"
0 Offers

Name     : zircon_transport_rust_next_child
Moniker  : dev.zircon_transport_rust_next_parent.zircon_transport_rust_next_child
Driver   : fuchsia-pkg://fuchsia.com/zircon_transport_rust_next#meta/zircon_transport_child.cm
1 Properties
[ 1/  1] : Key "fuchsia.hardware.i2c.Service" Value "fuchsia.hardware.i2c.Service.ZirconTransport"
1 Offers
Service: fuchsia.hardware.i2c.Service
  Source: dev.zircon_transport_rust_next_parent
  Instances: default

Name     : transport-child
Moniker  : dev.zircon_transport_rust_next_parent.zircon_transport_rust_next_child.transport-child
Driver   : unbound
1 Properties
[ 1/  1] : Key "fuchsia.test.TEST_CHILD"      Value "rust i2c server"
0 Offers

Testing

Include the tests to your build by appending --with-test //examples/drivers:hermetic_tests to your fx set command. For example:

$ fx set core.x64 --with //examples/drivers:drivers --with-test //examples/drivers:hermetic_tests
$ fx build

Run unit tests with the command:

$ fx test zircon-rust-next-driver

This will run unit tests against both the parent and child driver implementations.

Source layout

The core implementation of the parent driver is in parent/src/*.rs and the child driver is in child/src/*.rs.