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

Add Indexer trait implementation built with rangemap #9

Open
ekroon opened this issue Jan 3, 2023 · 1 comment
Open

Add Indexer trait implementation built with rangemap #9

ekroon opened this issue Jan 3, 2023 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@ekroon
Copy link
Owner

ekroon commented Jan 3, 2023

Description

After implementation, something like this should work:

StringSpark::<BuildRangemapIndexer>::default().spark(data)

Links

@ekroon ekroon added the enhancement New feature or request label Jan 3, 2023
@ekroon
Copy link
Owner Author

ekroon commented Jan 6, 2023

When implementing this, it breaks the defaulted version.

struct StringSpark<T=BuildAlgorithmicIndexer> { ... } 
StringSpark::default().spark(data); // doesn't compile because -> type annotations needed for `StringSpark<T>`

This is a known issue / design implementation in Rust, where StringSpark::default() does type inference without fallback to default types. There are work-arounds:

<StringSpark>::default().spark(data); 
let s: StringSpark = StringSpark::default();
s.spark(data);

The difference is that in Type location the Rust compiler will use fill in type parameters, BUT in a Path expression everything will be inferred.

let _ = StringSpark::default(); // StringSpark in path expression only, so defaults to StringSpark<_> which cannot be solved

// Following is the same, SpringSpark is also in Type location. 
let _: StringSpark = StringSpark::default();
let _: StringSpark<BuildAlgorithmicIndexer> = StringSpark::<_>::default();

// This doesn't work because _ for T disables the default and uses inference
let _: StringSpark<_> = StringSpark::default();

// Using <SpringSpark> in a path expression will interpret SpringSpark within the brackets as a Type
let _ = <StringSpark>::default(); // this works, as T will be replaced with default
let _ = <StringSpark<_>>::default(); // Doesn't work as the inference replaces the default again.

Links

@ekroon ekroon added this to the Version 1.0 milestone Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant