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

extend CompactStringExt implementation #412

Open
asibahi opened this issue Nov 6, 2024 · 1 comment · May be fixed by #418
Open

extend CompactStringExt implementation #412

asibahi opened this issue Nov 6, 2024 · 1 comment · May be fixed by #418

Comments

@asibahi
Copy link

asibahi commented Nov 6, 2024

Hello.

I have been converting my discord bot to use CompactString throughout, mostly because I have nothing better to do tbh.

There is this snippet of code :

minion_types
    .iter()
    .map(|t| t.in_locale(self.1)) // `in_locale` returns `impl Display`
    .join("/") // <-- from itertools
    .to_compact_string()

I tried playing with it in different ways to avoid the String creation in the middle by join, but join_compact is not apparently implemented for Map.

For example when I change it to this

minion_types
    .iter()
    .map(|t| t.in_locale(self.1).to_compact_string()) // not sure what to do here.
    .join_compact("/")

I get this extra verbose error

error[E0599]: the method `join_compact` exists for struct `Map<Iter<'_, MinionType>, {[email protected]:161:10}>`, but its trait bounds were not satisfied
   --> mimiron/src/bg.rs:162:6
    |
159 | / minion_types
160 | |     .iter()
161 | |     .map(|t| t.in_locale(self.1).to_compact_string())
162 | |     .join_compact("/")
    | |     -^^^^^^^^^^^^ method cannot be called on `Map<Iter<'_, MinionType>, {[email protected]:161:10}>` due to unsatisfied trait bounds
    | |_____|
    |
    |
   ::: /Users/abdulrahmansibahi/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:61:1
    |
61  |   pub struct Map<I, F> {
    |   -------------------- doesn't satisfy `_: CompactStringExt`
    |
    = note: the following trait bounds were not satisfied:
            `<&'a std::iter::Map<std::collections::hash_set::Iter<'_, card_details::MinionType>, {closure@mimiron/src/bg.rs:161:10: 161:13}> as std::iter::IntoIterator>::Item = &'a _`
            which is required by `std::iter::Map<std::collections::hash_set::Iter<'_, card_details::MinionType>, {closure@mimiron/src/bg.rs:161:10: 161:13}>: compact_str::CompactStringExt`
            `&'a std::iter::Map<std::collections::hash_set::Iter<'_, card_details::MinionType>, {closure@mimiron/src/bg.rs:161:10: 161:13}>: std::iter::IntoIterator`
            which is required by `std::iter::Map<std::collections::hash_set::Iter<'_, card_details::MinionType>, {closure@mimiron/src/bg.rs:161:10: 161:13}>: compact_str::CompactStringExt`

I do not if I am missing something obvious or if this is a missing implementation from the library.

@ParkMyCar
Copy link
Owner

Thanks for the bug report @asibahi! This is indeed an issue in the library, I just put up #418 to fix this and will release it with a v0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants