3 releases
0.1.2 | Mar 13, 2024 |
---|---|
0.1.1 | Mar 12, 2024 |
0.1.0 | Mar 12, 2024 |
#568 in Procedural macros
15KB
101 lines
Caravel Export usage
cargo new --lib your_caravel_lib
cargo add caravel_export_poc
cargo add anyhow
cargo add serde --features derive
cargo add serde_json
Make sure your Cargo.toml has the below entry in the [lib] section.
crate-type = ["cdylib"]
Put the following proc macros on the struct you'd like to expose to Caravel in your library.
#[caravel_resource]
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct File {
pub path: PathBuf,
pub state: FileState,
pub owner: Option<String>,
pub group: Option<String>,
}
Then you must implement validate and apply function on your resourse with the following signature.
impl File {
fn validate(&self) -> Result<()> {
Ok(())
}
fn apply(&self) -> Result<()> {
Ok(())
}
}
When you compile the lib and use it with Caravel, the resulting .so,.dylib,.dll should be named the same as your resource. Example for dummy library above: File.so
Then you can drop it in the caravel_modules directory of your Caravel Project!
Dependencies
~230–670KB
~16K SLoC