rid::debug

Explains the Rid debug attribute.

Models that #[derive(Debug)]

If a struct or enum is annotated with #[rid::model] or #[rid::store] rid automatically detects if it derives Debug via #[derive(Debug)].

I such a derive is found then rid generates the following method for the raw Dart type representing that Rust type.

String debug([bool pretty = false]) { 
  // Call to Rust to obtain the Debug respresentation
}
  • passing true for pretty corresponds to format!("{:#?}", instance) to get a more verbose and readable String representation of the struct instance
  • passing false or omitting pretty corresponds to format!("{:?}", instance) to get a less verbose_String_ representation of the struct instance
print(Store.instance.debug(true));

Inclusion in Dart API

This debug method is not included in the Dart class generated for such structs as memory safety cannot be guaranteed since the pointer to the struct could become invalid from one call to the next.

For the Store however this debug method is included in the recommended Dart API as well since in this case it is memory safe since the Store pointer will never become invalid while the app is running.