diff --git a/example/main/c/main.c b/example/main/c/main.c index c75d457..5080c30 100644 --- a/example/main/c/main.c +++ b/example/main/c/main.c @@ -69,5 +69,17 @@ plugin_main () println ("Rust returned: %s", hi); string_free (hi); + // The API also has full support for custom types (the `Dog` and `TrainedDog` + // types are defined in the `api.tri` file) + struct Dog dog = { .name = "Bruce" }; + struct TrainedDog tDog; + if (!one.train_dog (&tDog, dog)) + handle_error (); + + println ("Dog %s is now trained with specialization %i", tDog.name, + tDog.training); + // Beware that you need to free them with the appropriate free functions + string_free (tDog.name); + return 0; } diff --git a/example/main/src/bin/main/api.tri b/example/main/src/bin/main/api.tri index 981bc02..b2a0eac 100644 --- a/example/main/src/bin/main/api.tri +++ b/example/main/src/bin/main/api.tri @@ -22,9 +22,38 @@ /// Call out an outstanding person fn outstanding(name: String); +enum DogTraining { + Sheep, + Wolf, + Blind, +} + +#[error] +enum TrainingMistake { + #[msg("The dog got bitten")] + GotBitten, + #[msg("The trainer died")] + Died, +} + mod one { + /// A Dog after extensive training + struct TrainedDog { + name: String, + training: DogTraining, + } /// Say hi to a name fn hi(name: String) -> String; + + /// Train a dog without using any resources + // fn cheaply_train_dog(dog: Dog) -> Result; + + /// Train a dog + fn train_dog(dog: Dog) -> TrainedDog; +} + +struct Dog { + name: String, } // Trixy is a subset of Rust