As far as I can tell, you can only get TypeBorrowed<'static> versions of structs without unsafe when using compile_data.
E.g. when using ComposingNormalizer, all interesting methods are on ComposingNormalizerBorrowed. ComposingNormalizer::new_nfc returns a ComposingNormalizerBorrowed<'static> for use with compile_data.
When using a baked data provider, the only alternative I see is to do e.g.
let normalizer = icu::normalizer::ComposingNormalizer::try_new_nfc_unstable(&BakedDataProvider).unwrap();
If implementing a struct that owns a ComposingNormalizer, you're then forced to call ComposingNormalizer ::as_borrowed whenever you need to actually use the normalizer.
Alternatively, you can use unsafe to create a ComposingNormalizerBorrowed<'static>, although it's unclear if this is actually safe or not:
let normalizer = icu::normalizer::ComposingNormalizer::try_new_nfc_unstable(&BakedDataProvider).unwrap();
let normalizer: icu::normalizer::ComposingNormalizerBorrowed<'static> =
unsafe { std::mem::transmute(normalizer.as_borrowed()) };
Am I doing something wrong? Is there a more ergonomic API that could be added here (or clarification added in the docs whether extending the lifetime here is safe or not)?
As far as I can tell, you can only get
TypeBorrowed<'static>versions of structs without unsafe when usingcompile_data.E.g. when using
ComposingNormalizer, all interesting methods are onComposingNormalizerBorrowed.ComposingNormalizer::new_nfcreturns aComposingNormalizerBorrowed<'static>for use withcompile_data.When using a baked data provider, the only alternative I see is to do e.g.
If implementing a struct that owns a
ComposingNormalizer, you're then forced to callComposingNormalizer ::as_borrowedwhenever you need to actually use the normalizer.Alternatively, you can use unsafe to create a
ComposingNormalizerBorrowed<'static>, although it's unclear if this is actually safe or not:Am I doing something wrong? Is there a more ergonomic API that could be added here (or clarification added in the docs whether extending the lifetime here is safe or not)?