Create a new Layer
A layer in Leaf can implement any behavior as long as it takes an input and produces an output. As Leaf is new, there are still many valuable layers that are not yet implemented. This is why this chapter shows how you can add new layers to Leaf.
A not exclusive list of steps to take in order to implement a new layer:
The Rust compiler is also very helpful with pointing out the necessary steps for implementing a new layer struct. It might be beneficial to start the implementation of a new layer from a copied file of an already existing layer.
-
Decide to which of the five types the new layer belongs. This decides under which directory to put the layer implementation in the Leaf project.
-
Create the
Layerworker struct. -
Expose the
Layerworker struct in themod.rsof the layer type directory. -
Expose the
Layerworker struct in themod.rsof the/layersdirectory. -
Implement
ILayerand its trait boundaries for the newLayerworker struct. -
Add the new layer to the
LayerTypeinlayer.rsand add the matching for.support_in_placeand.worker_from_config. -
If the new layer relies on a collenchyma operation, also add the collenchyma trait boundary.
-
Add documentation and serialization to the new layer.
-
(optional) Depending on how complex the layer is, you might also add tests and more advanced implementations for its
.from_config,.reshapeor other helper methods.