Comments (4)
I briefly experimented with a couple of ideas, the first was an inherent associated type:
impl Foo {
type Projection = __FooProjection;
}
that's currently unsupported (rust-lang/rust#8995) and would presumably require GATs.
The other idea was to add a trait that had an associated type, which would need GATs as well.
My experiments with GAT workarounds seem to indicate that you can't use associated types as the base type in an impl
block (impl Foo::Projection<'_> { ... }
) or the constructor type in a destructuring statement (let Foo::Projection { bar } = ...;
) anyway, so neither of those methods would work even if declaring the associated type worked.
from pin-project.
Another horrible idea I had was
mod Foo {
pub(super) type Projection<'a> = super::__FooProjection<'a>;
}
luckily modules and structs inhabit the same namespace so this is not possible.
from pin-project.
I am thinking about two ways.
The first is to use an attribute too impl Foo
and convert Foo
to __FooProjection
.
#[pin_project::project_impl]
impl Foo {
fn debug(&self) {}
}
// convert to..
impl<'__pin> __FooProjection<'__pin> {
fn debug(&self) {}
}
This way is almost the same as what the #[project]
attribute currently does for let
and match
.
Another way is to allow naming the projected-type via the #[pin_project]
attribute's argument.
#[pin_project::pin_project(projection = Bar)]
struct Foo {
#[pin]
bar: &'static str,
}
impl Bar<'_> {
fn debug(&self) {}
}
We need to document that new lifetimes will be added, but this may be the best solution for this issue and rust-lang/pin-utils#21 at this time.
from pin-project.
Oh yeah, I forgot about the #[project]
attribute, I've been meaning to take a look at what it actually does. So that already covers the latter usecase, and it would make sense to do something similar for both.
from pin-project.
Related Issues (20)
- pin_project cannot be used with structs that hold mutable references HOT 4
- "unused result" warning with 0.4.18 HOT 2
- ?Sized type parameters don't work
- Tracking issue for 1.0.0 release HOT 5
- Prepare for uplift of drop-bounds lint HOT 3
- Generated `#[deny(safe_packed_borrows)]` is not compatible with `#![forbid(future_incompatible)]` HOT 5
- #[pin_project] panics with `internal error: entered unreachable code` when used inside a MBE with vis HOT 2
- error: cannot find attribute `derive` in this scope HOT 3
- Rust-Analyzer compatibility HOT 7
- Cannot build with RUSTFLAGS="-Zsanitizer=address" HOT 2
- Leaked UB in enums HOT 10
- Ambiguous macro use does not compile HOT 3
- `parse_quote_spanned` macro name-collides with `syn::parse_quote_spanned` HOT 1
- #![feature(negative_impls)] breaks the guarantee for Unpin provided by pin-project HOT 1
- Can bypass #[repr(packed)] checking since rust 1.57 HOT 2
- Allow #[pin_project(!Unpin)] to `impl !Unpin` HOT 1
- provide project method on `&mut Pin<&mut Self>` HOT 2
- Why was 1.0.10 yanked from crates.io? HOT 6
- Pin-projecting in-line tuples HOT 2
- docs: Add FAQ section?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pin-project.