docs(example): Update the example c and tri file to latest progress
This commit is contained in:
parent
aa4391905a
commit
2ed6ed7f58
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<TrainedDog, TrainingMistake>;
|
||||
|
||||
/// Train a dog
|
||||
fn train_dog(dog: Dog) -> TrainedDog;
|
||||
}
|
||||
|
||||
struct Dog {
|
||||
name: String,
|
||||
}
|
||||
|
||||
// Trixy is a subset of Rust
|
||||
|
|
Reference in New Issue