Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Lenra's app lib for Rust apps
https://github.com/lenra-io/app-lib-rust

app-lib hacktoberfest lenra rust rust-lang

Last synced: about 2 months ago
JSON representation

Lenra's app lib for Rust apps

Awesome Lists containing this project

README

        


[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]




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](https://github.com/lenra-io/app-lib-rust/issues)
·
[Request Feature](https://github.com/lenra-io/app-lib-rust/issues)

## Usage

To add it to your Lenra app project:
```console
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:
```rust
#[derive(Serialize, Deserialize, Debug, PartialEq, Default, Clone)]
pub struct CustomType {
#[serde(rename = "_id")]
pub id: Option,
pub value: String,
}

impl Doc for CustomType {
fn id(&self) -> Option {
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) -> 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](./LICENSE) for more information.

(back to top)

## Contact

Lenra - [@lenra_dev](https://twitter.com/lenra_dev) - [email protected]

Project Link: [https://github.com/lenra-io/app-lib-rust](https://github.com/lenra-io/app-lib-rust)

(back to top)

[contributors-shield]: https://img.shields.io/github/contributors/lenra-io/app-lib-rust.svg?style=for-the-badge
[contributors-url]: https://github.com/lenra-io/app-lib-rust/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/lenra-io/app-lib-rust.svg?style=for-the-badge
[forks-url]: https://github.com/lenra-io/app-lib-rust/network/members
[stars-shield]: https://img.shields.io/github/stars/lenra-io/app-lib-rust.svg?style=for-the-badge
[stars-url]: https://github.com/lenra-io/app-lib-rust/stargazers
[issues-shield]: https://img.shields.io/github/issues/lenra-io/app-lib-rust.svg?style=for-the-badge
[issues-url]: https://github.com/lenra-io/app-lib-rust/issues
[license-shield]: https://img.shields.io/github/license/lenra-io/app-lib-rust.svg?style=for-the-badge
[license-url]: https://github.com/lenra-io/app-lib-rust/blob/master/LICENSE.txt