Crates.io | caravel_export_poc |
lib.rs | caravel_export_poc |
version | 0.1.2 |
source | src |
created_at | 2024-03-12 20:15:33.800881 |
updated_at | 2024-03-13 00:09:04.550201 |
description | Caravel Module Wrapper |
homepage | |
repository | https://github.com/pkmollman/caravel_export_poc |
max_upload_size | |
id | 1170990 |
size | 41,664 |
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!