#lib #api #app #lenra

lenra-app

App Lib for Rust Lenra apps

5 releases (2 stable)

1.0.1 Oct 6, 2023
1.0.0 Sep 29, 2023
1.0.0-beta.2 Jul 15, 2023
1.0.0-beta.1 Apr 24, 2023

#9 in #app

36 downloads per month

MIT license

1MB
22K SLoC

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)

Dependencies

~8–11MB
~236K SLoC