Skip to content

Ergonomics involving borrow structures and baked data providers #6058

Answered by sffc
csmulhern asked this question in Q&A
Discussion options

You must be logged in to vote

You are correct that the only way to create a ComposingNormalizerBorrowed<'static> is to use compiled data; the reason is that compiled data exports singleton statics that bypass the DataProvider trait.

In general, casting the return value of as_borrowed to 'static is unsound (unless perhaps you have it saved in a static OnceLock or something). However, calling as_borrowed is very cheap (though not 100% free: #5187). The idea is that if you need to call one of the terminal functions such as normalize multiple times, you can call as_borrowed just once.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by csmulhern
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@sffc
Comment options

sffc Feb 2, 2025
Maintainer

@csmulhern
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #6053 on February 02, 2025 10:29.