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

Feature: naive support for const param generics. #106

Merged
merged 4 commits into from Dec 10, 2023

Conversation

Y-jiji
Copy link
Contributor

@Y-jiji Y-jiji commented Dec 10, 2023

My Case:
When I was working on creating a scanner for log structured merge tree, I have to implement a Scanner trait that supports scanning keys inside a key range.
It features:

  • either a forward or reverse scan.
  • keep the scanned block on disk (which means the underlying iterator self-references an Arc)
    Therefore, I have to write a type like:
pub trait Scannable {
    type K; type V;
    type Scanner<'a, const RVS: bool>:
        for<'b> IteratorExt<Item<'b> = (&'b Self::K, &'b Self::V)>
        where Self: 'a;
    fn scan<const RVS: bool>(&self, range: impl RangeBounds<Self::K>) -> Self::Scanner<'_, RVS>;
}

/// with reference
#[ouroboros::self_referencing]
pub struct SelfRefScanner<T, const RVS: bool>
where
    T: Scannable + 'static,
{
    orig: Arc<T>,
    #[borrows(orig)]
    #[not_covariant]
    proj: T::Scanner<'this, RVS>,
}

Changed Behaviour:
In current implementation the macro panics without giving any reason, as suggested in #47 .
The tweaked implementation supports constant parameters.

Soundness:
Since the added constants don't carry additional data from runtime, it doesn't effect validity.
Since the number of added constants are finite, an exhausting the finite space proofs type safety, as long as the compiler doesn't raise any errors.

@Y-jiji
Copy link
Contributor Author

Y-jiji commented Dec 10, 2023

@joshua-maros I need this badly. Please merge ASAP if there exists no further concerns.

@someguynamedjosh someguynamedjosh merged commit 1383a6a into someguynamedjosh:main Dec 10, 2023
6 checks passed
@someguynamedjosh
Copy link
Owner

LGTM, I've published this as version 0.18.1.

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

Successfully merging this pull request may close these issues.

None yet

2 participants