Skip to content

lenra-io/app-lib-rust

Repository files navigation

Contributors Forks Stargazers Issues MIT License


App Lib for Rust based Lenra projects

This lib integrates all the elements the app needs in order to only keep the views, listeners and resources in the app project.

Report Bug · Request Feature

Usage

To add it to your Lenra app project:

cargo add lenra-app@~1.0.0-beta.0

Lenra API calls

To call the Lenra API from a listener, just use the Api instance in the parameter of your listener function.

You can then call the data API like that to create a document:

#[derive(Serialize, Deserialize, Debug, PartialEq, Default, Clone)]
pub struct CustomType {
    #[serde(rename = "_id")]
    pub id: Option<String>,
    pub value: String,
}

impl Doc for CustomType {
    fn id(&self) -> Option<String> {
        match &self.id {
            Some(x) => Some(x.clone()),
            None => None,
        }
    }
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
pub struct CustomProps {
    value: String,
}
// Use the props! macro to generate the props struct automatically
props!(CustomProps);

fn my_listener(params: ListenerParams<CustomProps, Value>) -> Result<()> {
    let my_doc: CustomType = params.api.data.create_doc(
        COUNTER_COLLECTION,
        CustomProps {
            value: CustomProps.value,
            ..Default::default()
        },
    )?;
    Ok(())
}

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please open an issue with the tag "enhancement" or "bug". Don't forget to give the project a star! Thanks again!

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Lenra - @lenra_dev - contact@lenra.io

Project Link: https://github.com/lenra-io/app-lib-rust

(back to top)