Allow constructing an empty GlobSet in const #3098
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My use case: I have a struct that contains a GlobSet, among other information:
and some instances of this struct held in a different data structure — imagine this is akin to Cargo.toml's
[dependencies]
and[target.'cfg(…)'.dependencies]
:and a function where it would be really convenient to be able to use a const to get a sufficiently long-lived reference to a static Thing containing an empty globset:
Without being able to call
GlobSet::empty()
in const, I would need to do one of the following workarounds instead:Store
Option<GlobSet>
instead of justGlobSet
, whereNone
means the same thing asGlobSet::empty()
.Find a place to put my constant Thing at runtime, either inside
ConfigFile
(awkward) or some other storage that is passed in tothings
(awkward).Switch to
Cow<'_, Thing>
and sprinkle the implementation ofthings
withCow::Owned
andmap(Cow::Borrowed)
.Clone everything every time we iterate this data structure.
Something with a
static
OnceLock
.