Skip to content

Commit

Permalink
docs and doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed May 11, 2023
1 parent 678b81d commit 281b591
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 2 additions & 4 deletions crux_core/tests/typegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ mod shared {
}

mod test {
use super::shared::{App, EffectFfi, Event};
use crux_core::{bridge::Request, typegen::TypeGen};
use super::shared::{App, Event};
use crux_core::typegen::TypeGen;
use uuid::Uuid;

// FIXME this test is quite slow
#[test]
fn generate_types() {
let mut gen = TypeGen::new();

gen.register_type::<Request<EffectFfi>>().unwrap();

let sample_events = vec![Event::SendUuid(Uuid::new_v4())];
gen.register_type_with_samples(sample_events).unwrap();

Expand Down
6 changes: 2 additions & 4 deletions crux_http/tests/with_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ mod shell {

mod tests {
use crate::{
shared::{App, Effect, EffectFfi, Event},
shared::{App, Effect, Event},
shell::run,
};
use anyhow::Result;
use crux_core::{bridge::Request, typegen::TypeGen, Core};
use crux_core::{typegen::TypeGen, Core};
use crux_http::protocol::HttpRequest;

#[test]
Expand Down Expand Up @@ -187,8 +187,6 @@ mod tests {
fn generate_types() {
let mut gen = TypeGen::new();

gen.register_type::<Request<EffectFfi>>().unwrap();

gen.register_app::<App>().unwrap();

let registry = match gen.state {
Expand Down
13 changes: 12 additions & 1 deletion docs/src/getting_started/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,23 @@ This crate serves as the container for type generation for the foreign languages

- Copy over the [shared_types](https://github.com/redbadger/crux/tree/master/examples/counter/shared_types) folder from the counter example.

- Edit the `build.rs` file and make sure that your app type is registered. You may also need to register any nested enum types (due to a current limitation with the reflection library, see <https://github.com/zefchain/serde-reflection/tree/main/serde-reflection#supported-features>). Here is an example of this from the [`build.rs`](https://github.com/redbadger/crux/blob/master/examples/notes/shared_types/build.rs) file in the `shared_types` crate of the `notes` example:
- Edit the `build.rs` file and make sure that your app type is registered. You may also need to register any nested enum types (due to a current limitation with the reflection library, see <https://github.com/zefchain/serde-reflection/tree/main/serde-reflection#supported-features>). Here is an example of this from the [`build.rs`](https://github.com/redbadger/crux/blob/master/examples/notes/shared_types/build.rs) file in the `shared_types` crate of the [notes example](https://github.com/redbadger/crux/tree/master/examples/notes):

```rust
{{#include ../../../examples/notes/shared_types/build.rs}}
```

```admonish note
For the above to compile, your `Capabilities` struct must implement the `Export` trait. There is a derive macro that can do this for you, e.g.:
#[derive(crux_macros::Effect, crux_macros::Export)]
pub struct Capabilities {
pub render: Render<Event>,
pub http: Http<Event>,
}
```

- Make sure everything builds and foreign types get generated into the `generated` folder.

```sh
Expand Down

0 comments on commit 281b591

Please sign in to comment.