Skip to content
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

index_map and character_map are broken (one static map is initialized for all types, and thus doesn't work for different types) #229

Closed
Trolldemorted opened this issue Mar 7, 2024 · 0 comments · Fixed by #230
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/bug Something isn't working

Comments

@Trolldemorted
Copy link
Contributor

As discussed in ferrilab/bitvec#229 (comment), the current index_map and character_map functions are broken:

fn index_map() -> &'static alloc::collections::BTreeMap<u32, u32> {
static MAP: OnceBox<BTreeMap<u32, u32>> = OnceBox::new();
MAP.get_or_init(|| {
Box::new(
Self::CHARACTER_SET
.iter()
.copied()
.enumerate()
.map(|(i, e)| (e, i as u32))
.collect(),
)
})
}

The static MAP: OnceBox<BTreeMap<u32, u32>> exists once for all implementing types, not separately for each implementing type.

@XAMPPRocky XAMPPRocky added kind/bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers area/codec Related to a new or existing ASN.1 codec. labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants