bevy/crates/bevy_reflect/src
Marco Buono a475511f43
Add method for querying whether a given short type path is ambiguous (#11840)
# Objective

Currently, the `ambiguous_names` hash set in `TypeRegistry` is used to
keep track of short type names that are ambiguous, and to require the
use of long type names for these types.

However, there's no way for the consumer of `TypeRegistry` to known
whether a given call to `get_with_short_type_path()` or
`get_with_short_type_path_mut()` failed because a type was not
registered at all, or because the short name is ambiguous.

This can be used, for example, for better error reporting to the user by
an editor tool. Here's some code that uses this, from my remote protocol
exploration branch:

```rust
let type_registration = type_registry
  .get_with_type_path(component_name)
  .or_else(|| registry.get_with_short_type_path(component_name))
  .ok_or_else(|| {
      if type_registry.is_ambiguous(component_name) {
          BrpError::ComponentAmbiguous(component_name.clone())
      } else {
          BrpError::MissingTypeRegistration(component_name.clone())
      }
  })?
```

## Solution

- Introduces a `is_ambiguous()` method.
- Also drive-by fixes two documentation comments that had broken links.

---

## Changelog

- Added a `TypeRegistry::is_ambiguous()` method, for checking whether a
given short type path is ambiguous (e.g. `MyType` potentially matching
either `some_crate::MyType` or `another_crate::MyType`)

---------

Co-authored-by: François <mockersf@gmail.com>
2024-02-19 16:47:11 +00:00
..
enums Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
impls Rework animation to be done in two phases. (#11707) 2024-02-19 14:59:54 +00:00
path Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
serde Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
array.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
fields.rs reflect: TypePath part 2 (#8768) 2023-10-09 19:33:03 +00:00
from_reflect.rs reflect: TypePath part 2 (#8768) 2023-10-09 19:33:03 +00:00
lib.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
list.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
map.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
reflect.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
std_traits.rs
struct_trait.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
tuple_struct.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
tuple.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
type_info.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
type_path.rs Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
type_registry.rs Add method for querying whether a given short type path is ambiguous (#11840) 2024-02-19 16:47:11 +00:00
utility.rs Rework animation to be done in two phases. (#11707) 2024-02-19 14:59:54 +00:00