rust-lang / keyword-generics-initiative

Public repository for the Rust keyword generics initiative
https://rust-lang.github.io/keyword-generics-initiative/
Other
96 stars 11 forks source link

Create postfix-question-mark.md #21

Closed tvallotton closed 1 year ago

tvallotton commented 1 year ago

Design

base (reference)

/// A trimmed-down version of the `std::Iterator` trait.
pub trait async? Iterator {
    type Item;
    async? fn next(&mut self) -> Option<Self::Item>;
    fn size_hint(&self) -> (usize, Option<usize>);
}

/// An adaptation of `Iterator::find` to a free-function
pub async? fn find<I, T, P>(iter: &mut I, predicate: P) -> Option<T>
where
    I: async? Iterator<Item = T> + Sized,
    P: FnMut(&T) -> bool;

always async

/// An adaptation of `Iterator::find` to a free-function
pub async fn find<I, T, P>(iter: &mut I, predicate: P) -> Option<T>
where
    I: async Iterator<Item = T> + Sized,
    P: FnMut(&T) -> bool;

maybe async

pub async? fn find<I, T, P>(iter: &mut I, predicate: P) -> Option<T>
where
    I: async? Iterator<Item = T> + Sized,
    P: FnMut(&T) -> bool;

generic over all modifier keywords

/// A trimmed-down version of the `std::Iterator` trait.
pub trait effect Iterator {
    type Item;
    effect fn next(&mut self) -> Option<Self::Item>;
    fn size_hint(&self) -> (usize, Option<usize>);
}

Notes

This is just a postfix version of the originally proposed syntax. This should appear more familiar, as the question mark is normally used at the end of a sentence, not at the beginning, and it looks similar to typescripts nullable types. it also makes generic references more legible &mut? T vs &?mut T.

clarfonthey commented 1 year ago

Note: you typoed postfix as postix here.

tvallotton commented 1 year ago

@clarfonthey oops, thank you for mentioning it.