pub trait ModuleId:
Any
+ Display
+ Send
+ Sync {
// Required method
fn clone_boxed(&self) -> Box<dyn ModuleId>;
}
Expand description
Identifier of an ExecutableModule
. This is usually a “small” type,
such as an integer or a string.
The ID is provided when creating a module. It is displayed
in error messages (using Display::fmt
). ModuleId
is also associated with some types
(e.g., InterpretedFn
and CodeInModule
), which allows to obtain module info.
This can be particularly useful for outputting rich error information.
A ModuleId
can be downcast to a specific type, similarly to Any
.
Required Methods§
Sourcefn clone_boxed(&self) -> Box<dyn ModuleId>
fn clone_boxed(&self) -> Box<dyn ModuleId>
Clones this module ID and boxes the result. It is expected that the output will have the same specific type as the original module ID. This operation is generally expected to be quite cheap.
Implementations§
Source§impl dyn ModuleId
impl dyn ModuleId
Sourcepub fn is<T: ModuleId>(&self) -> bool
pub fn is<T: ModuleId>(&self) -> bool
Returns true
if the boxed type is the same as T
.
This method is effectively a carbon copy of <dyn Any>::is
. Such a copy is necessary
because &dyn ModuleId
cannot be converted to &dyn Any
, despite ModuleId
having Any
as a super-trait.
Sourcepub fn downcast_ref<T: ModuleId>(&self) -> Option<&T>
pub fn downcast_ref<T: ModuleId>(&self) -> Option<&T>
Returns a reference to the boxed value if it is of type T
, or None
if it isn’t.
This method is effectively a carbon copy of <dyn Any>::downcast_ref
. Such a copy
is necessary because &dyn ModuleId
cannot be converted to &dyn Any
, despite ModuleId
having Any
as a super-trait.