-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DataPayload::dynamic_cast with example #5467
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be applied to the tutorials:
icu4x/tutorials/data_provider.md
Lines 218 to 219 in 1426a7e
let mut any_payload = (&mut res.payload) as &mut dyn Any; | |
if let Some(mut decimal_payload) = any_payload.downcast_mut::<DataPayload<DecimalSymbolsV1Marker>>() { |
/// { | ||
/// #[inline] | ||
/// fn load(&self, req: DataRequest) -> Result<DataResponse<M>, DataError> { | ||
/// if TypeId::of::<HelloWorldV1Marker>() == TypeId::of::<M>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere we compare data markers types we compare M::INFO
. Comparing TypeId::of::<M>()
is a new way to do this and we should agree on one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, interesting observation.
If we have access to both marker types, comparing TypeId
is probably more efficient. There might still be cases where we have a DynamicDataMarker
and we have to compare the INFO
.
|
Right, the tutorial should use |
I came across this in the context of the transliteration example. Adding this function makes forking providers easier to write.