Skip to content

Commit

Permalink
Merge pull request #3 from danielhenrymantilla/next
Browse files Browse the repository at this point in the history
Version 0.1.3
  • Loading branch information
danielhenrymantilla authored Jul 21, 2022
2 parents 07e71e9 + dac9433 commit ad6ed19
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "lending-iterator"
authors = [
"Daniel Henry-Mantilla <[email protected]>",
]
version = "0.1.2" # Keep in sync
version = "0.1.3" # Keep in sync
edition = "2021"

license = "Zlib OR MIT OR Apache-2.0"
Expand All @@ -18,7 +18,13 @@ readme = "README.md"
rust-version = "1.57.0"

description = "Fully general lending iterators in stable rust: windows_mut!"
keywords = ["rust-patterns"]
keywords = [
"streaming",
"streaming-iterator",
"windows_mut",
"hkt",
"gat",
]

[features]
default = [
Expand Down Expand Up @@ -50,7 +56,7 @@ macro-vis.version = "0.1.1"

[dependencies.lending-iterator-proc_macros]
path = "src/proc_macros"
version = "0.1.2" # Keep in sync
version = "0.1.3" # Keep in sync

[dev-dependencies]

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# `::lending-iterator`

Fully generic `LendingIterator`s in stable Rust.

[![Repository](https://img.shields.io/badge/repository-GitHub-brightgreen.svg)](
https://github.com/danielhenrymantilla/lending-iterator.rs)
[![Latest version](https://img.shields.io/crates/v/lending-iterator.svg)](
Expand All @@ -19,6 +17,8 @@ https://github.com/danielhenrymantilla/lending-iterator.rs/actions)

<!-- Templated by `cargo-generate` using https://github.com/danielhenrymantilla/proc-macro-template -->

Fully generic `LendingIterator`s in stable Rust.

- this pattern used to be called `StreamingIterator`, but since [`Stream`](
https://docs.rs/futures/0.3.21/futures/stream/trait.Stream.html)s entered
the picture (as the `async/.await` version of `Iterator`s, that is,
Expand All @@ -44,7 +44,7 @@ https://github.com/danielhenrymantilla/lending-iterator.rs/actions)

## Examples

<details open><summary>Click to hide</summary>
<details open class="custom"><summary><span class="summary-box">Click to see/hide</span></summary>

### `windows_mut()`!

Expand Down Expand Up @@ -134,7 +134,7 @@ As noted in this **6-year-old issue**:

Such an API can easily be provided using the HKT API of this crate:

<details><summary>Click to see</summary>
<details class="custom"><summary><span class="summary-box">Click to see/hide</summary>

```rust
use ::lending_iterator::higher_kinded_types::{*, Apply as A};
Expand All @@ -145,10 +145,10 @@ fn slice_sort_by_key<Key, Item, KeyGetter> (
)
where
Key : HKT, // "Key : <'_>"
for<'any>
A!(Key<'any>) : Ord
KeyGetter : for<'item> FnMut(&'item Item) -> A!(Key<'item>),
for<'item>
A!(Key<'item>) : Ord
,
KeyGetter : FnMut(&Item) -> A!(Key<'_>),
{
slice.sort_by(|a, b| Ord::cmp(
&get_key(a),
Expand All @@ -160,7 +160,8 @@ where

struct Client { key: String, version: u8 }

fn main() {
fn main ()
{
let clients: &mut [Client] = &mut [];

// Error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
Expand Down
23 changes: 0 additions & 23 deletions bacon.toml

This file was deleted.

62 changes: 61 additions & 1 deletion fix-docsrs-li-details-summary.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
<style>
summary {
details.custom > summary {
display: list-item;
/* https://medium.com/simple-human/buttons-shouldnt-have-a-hand-cursor-b11e99ca374b */
cursor: default;
}

.summary-box {
display: inline-block;
}

details.custom > summary span.summary-to-hide,
details[open].custom > summary span.summary-to-see {
display: none;
}
details.custom > summary span.summary-to-see,
details[open].custom > summary span.summary-to-hide {
display: inline;
}

/**
* Button style from https://github.com/ubuwaits/css3-buttons
* MIT-Licensed under the name of Chad Mazzola
* rev: c5d2eccd18c0be21c291982e40da0c590f8bc32f
*
* I changed the following: I removed the padding, the width and `cursor: pointer`.
**/
.summary-box {
background-color: #eeeeee;
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #eeeeee), color-stop(100%, #cccccc));
background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
background-image: linear-gradient(top, #eeeeee, #cccccc);
border: 1px solid #ccc;
border-bottom: 1px solid #bbb;
border-radius: 3px;
color: #333;
font: bold 11px/1 "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
/* padding: 8px 0; */
text-align: center;
text-shadow: 0 1px 0 #eee;
/* width: 150px; */
}
.summary-box:hover {
background-color: #dddddd;
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #dddddd), color-stop(100%, #bbbbbb));
background-image: -webkit-linear-gradient(top, #dddddd, #bbbbbb);
background-image: -moz-linear-gradient(top, #dddddd, #bbbbbb);
background-image: -ms-linear-gradient(top, #dddddd, #bbbbbb);
background-image: -o-linear-gradient(top, #dddddd, #bbbbbb);
background-image: linear-gradient(top, #dddddd, #bbbbbb);
border: 1px solid #bbb;
border-bottom: 1px solid #999;
/* cursor: pointer; */
text-shadow: 0 1px 0 #ddd;
}
.summary-box:active {
border: 1px solid #aaa;
border-bottom: 1px solid #888;
-webkit-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
}
</style>
16 changes: 8 additions & 8 deletions src/higher_kinded_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### What are Higher-Kinded Types?

<details><summary>Click to see</summary>
<details class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>

A higher-kinded type is an actual / **full / standalone** type which is, itself,
"generic", or rather, to which we can further feed generic parameters (such as
Expand Down Expand Up @@ -99,11 +99,11 @@ HKTs come into play the moment we need "generic generics".

### Why? What are Higher-Kinded Types _for_?

<details><summary>Click to see</summary>
<details class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>

- #### Type-HKTs

<details><summary>Click to see</summary>
<details class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>

Consider the following pseudo-code:

Expand Down Expand Up @@ -172,7 +172,7 @@ HKTs come into play the moment we need "generic generics".

- #### Lifetime HKTs

<details open><summary>Click to hide</summary>
<details open class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>

Another use case can be around lifetimes, when dealing with higher-order
lifetimes (_e.g._, when exposing borrows of callee local variables to a
Expand Down Expand Up @@ -442,7 +442,7 @@ HKTs come into play the moment we need "generic generics".
### How? → Back to real Rust
<details><summary>Click to see</summary>
<details class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>
This, in real Rust, comes with three challenges:
Expand Down Expand Up @@ -626,7 +626,7 @@ trait HKT = for<'any> WithLifetime<'any>;
## The three important things to remember when working with these HKT APIs
<details open><summary>Click to hide</summary>
<details open class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>
1. **APIs use `T : HKT` to express `T : <'lt>`**
Expand Down Expand Up @@ -735,7 +735,7 @@ trait HKT = for<'any> WithLifetime<'any>;
## Illustration: fully working code for the `debug_each` example
<details><summary>Click to see</summary>
<details class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>
```rust
#![forbid(unsafe_code)]
Expand Down Expand Up @@ -804,7 +804,7 @@ fn main ()
RefCell::new(Person {
name: "".into(),
surname: "Globby".into(),
age: 255,
age: 0xff,
}),
];
let elems = &array[..];
Expand Down
54 changes: 24 additions & 30 deletions src/lending_iterator/_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Item<'lt, I : LendingIterator> =
/// type of the `fn next(&'_ mut self)` method being allowed to depend on that
/// `'_`**.
///
/// <details open><summary>Click to hide</summary>
/// <details open class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>
///
/// - That type is called the `Item<'_>` type, and is a
/// [`generic_associated_type`](#a-generic-associated-type).
Expand Down Expand Up @@ -178,7 +178,7 @@ type Item<'lt, I : LendingIterator> =
/// It does come with a few caveats, though: **the `LendingIterator::Item` item
/// is no longer really nameable**, at least not _directly_.
///
/// - The current implementation of [`::nougat]` uses a helper _higher-order_
/// - The current implementation of [`::nougat`] uses a helper _higher-order_
/// super-trait, called
/// <code>for\<\'any\> [LendingIteratorඞItem]\<\'any\></code>, which has,
/// itself, a non-generic associated type, `::T`. That way,
Expand All @@ -187,13 +187,13 @@ type Item<'lt, I : LendingIterator> =
///
/// **BUT THIS MAY change within semver-compatible changes of `nougat`**
///
/// Thence why that path should never be used, directly, by downstream code.
/// That's why that path should never be used, directly, by downstream code.
///
/// The only reason I am even talking about it and not having it
/// `#[doc(hidden)]` is that exposing it makes understanding the signatures
/// of the adapters multiple order of magnitude easier.
///
/// Thence the following "rules":
/// Hence the following "rules":
///
/// - Use <code>[Item]\<\'_, I\></code> instead of `I::Item<'_>`.
///
Expand Down Expand Up @@ -659,6 +659,7 @@ where
///
/// [Box]: ::alloc::boxed::Box
/// [CanonicalHKT]: crate::prelude::CanonicalHKT
#[apply(cfg_alloc)]
fn dyn_boxed_auto<BoxedDynLendingIterator, Item : HKT> (self: Self)
-> BoxedDynLendingIterator
where
Expand All @@ -670,34 +671,27 @@ where
)}

macro_rules! pervasive_hkt_choices {(
$(
($map:ident, $Map:ident)(
$(
$(#[$attr:meta])*
$fname:ident: [$($R:tt)*], $HKT:ty, -> $Ret:ty,
)*
),
)*
) => (
$(
($map:ident, $Map:ident)(
$(
$(#[$attr])*
fn $fname<$($R)*, F> (
self: Self,
f: F,
) -> $Map<Self, F, $HKT>
where
for<'any>
F : FnMut(
[&'any Self; 0],
Item<'any, Self>,
) -> $Ret
,
Self : Sized,
{
self.$map::<$HKT, F>(f)
}
$(#[$attr:meta])*
$fname:ident: [$($R:tt)*], $HKT:ty, -> $Ret:ty,
)*
) $(,)?
) => (
$(
$(#[$attr])*
fn $fname<$($R)*, F> (
self: Self,
f: F,
) -> $Map<Self, F, $HKT>
where
for<'any>
F : FnMut([&'any Self; 0], Item<'any, Self>) -> $Ret
,
Self : Sized,
{
self.$map::<$HKT, F>(f)
}
)*
)} use pervasive_hkt_choices;

Expand Down
2 changes: 1 addition & 1 deletion src/lending_iterator/adapters/_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! # Example
//!
//! <details open><summary>Click to hide</summary>
//! <details open class="custom"><summary><span class="summary-box"><span class="summary-to-see">Click to see</span><span class="summary-to-hide">Click to hide</span></span></summary>
//!
/*! - ```rust
use ::lending_iterator::prelude::*;
Expand Down
10 changes: 1 addition & 9 deletions src/lending_iterator/adapters/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ where
self: &'_ mut Filter<I, F>,
) -> Option<Item<'_, I>>
{
use ::polonius_the_crab::prelude::*;
let mut iter = &mut self.iter;
polonius_loop!(|iter| -> Option<Item<'polonius, I>> {
let ret = iter.next();
if matches!(ret, Some(ref it) if (self.should_yield)(it).not()) {
polonius_continue!();
}
polonius_return!(ret);
})
self.iter.find(&mut self.should_yield)
}
}
2 changes: 1 addition & 1 deletion src/proc_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "lending-iterator-proc_macros"
authors = [
"Daniel Henry-Mantilla <[email protected]>"
]
version = "0.1.2" # Keep in sync
version = "0.1.3" # Keep in sync
edition = "2021"

license = "Zlib OR MIT OR Apache-2.0"
Expand Down

0 comments on commit ad6ed19

Please sign in to comment.