Components
The value of Strut primarily comes from the components, which are included via Cargo features on the strut crate.
Component structure
A typical Strut component takes a popular Rust crate and removes boilerplate code required to configure or use that crate. Possible customization choices are externalized into config, and any trivial setup/spindown logic is moved under the hood.
Such component would usually have some combination of the following:
☑︎ Configuration section
A config section is a de-serializable struct that is included at the top level of AppConfig.
- Example:
TracingConfigfrom the tracing component. - These structs enable deserialization from empty, partial, or fuzzy input.
☑︎ Startup logic
- Example: setting global subscriber from the tracing component.
- This is normally called from a
Launchpadwiring.
☑︎ Client-facing facade.
- Example:
Databasefrom the database component. - A facade exposes associated functions that return pre-fabricated objects, such as database connection pools.
☑︎ Spindown logic.
- Example: closing database connections before the process exits.
- A component registers itself in the spindown registry; waits for the application context to terminate; performs spindown duties; then signals back to the registry that it completed gracefully.
Conventions
API re-export
When the underlying third-party crate is intended to be used after configuration, Strut typically re-exports that crate’s public API, either fully or partially.
For example, the tracing component re-esports parts of the tracing crate’s API under the strut::tracing::* module.
The idea is that after enabling the Strut component, there is no need to depend also on the underlying crate.
Contributing
Strut could always use more components.
While, custom integrations are possible in the client code, a component is most convenient when the strut crate is aware of it.
We are maintaining an open door contribution policy.
If you have an eye on a popular Rust crate that could use some boilerplate trimming, you have options to contribute to Strut:
- If you just want to raise awareness — check out our GitHub issues.
- Search for and upvote the petition to add your crate.
- Or create a new petition if your crate isn’t yet mentioned.
- If you feel like contributing your code and efforts — firstly, thank you.
- Our Discord server is the place to go for discussions and advice.
- You may also want to check out our
CONTRIBUTING.md.