Comments (7)
I was working on something very similar to this, but never quite finished. I can finish it up and open a PR.
from pin-project.
It seems that this can be replaced by wrapping the unpinned field with an Option.
#[pin_project]
enum Example {
A(#[pin] PinnedValue),
B(Option<UnpinnedValue>),
C,
}
#[project]
match self.as_mut().project() {
Example::A(_) => { /* ... */ },
Example::B(value @ Some(_)) => {
let value = value.take().unwrap();
// ...
},
Example::B(None) | Example::C => {},
}
self.set(Example::C); // When using this way, whether you should replace self depends on the situation.
from pin-project.
It seems reasonable to add this, given that it increases the size if use Option and that we cannot easily change the public type signature.
from pin-project.
Assigning to @Aaron1011 based on the previous comment (feel free to unassign).
from pin-project.
IIUC, macro needs to generate an additional struct/enum to support this.
@Aaron1011: Do you think it preferable to add a feature like #124 to implement this? (I feel the existing project-attribute-based approach becomes bothered as more types are generated.)
from pin-project.
In order to be panic-safe, it will need to generate code something like:
struct DropInPlaceHelper<T>(*mut T);
impl<T> DropInPlaceHelper<T> {
fn drop(&mut self) {
ptr::drop_in_place(self.0);
}
}
struct OverwriteHelper<T>(*mut T, MaybeUninit<T>);
impl<T> OverwriteHelper<T> {
fn drop(&mut self) {
ptr::write(self.0, self.1.assume_init());
}
}
fn partial_replace(ptr: *mut Foo, new_value: Foo) -> Y {
let _helper0 = OverwriteHelper(ptr, MaybeUninit::new(new_value));
let _helper1 = DropInPlaceHelper(&mut (*ptr).pinned_field1);
let _helper2 = DropInPlaceHelper(&mut (*ptr).pinned_field2);
let _helper3 = DropInPlaceHelper(&mut (*ptr).pinned_field3);
ptr::read(&mut (*ptr).unpinned_field)
}
from pin-project.
(Maybe we need to wait for rust-lang/unsafe-code-guidelines#232 discussion?)
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.