Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A crate for safe and ergonomic pin-projection.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

taiki-e/pin-project

crates.iodocs.rslicensemsrvgithub actions

A crate for safe and ergonomicpin-projection.

Usage

Add this to yourCargo.toml:

[dependencies]pin-project ="1"

Examples

#[pin_project] attribute creates projection typescovering all the fields of struct or enum.

use std::pin::Pin;use pin_project::pin_project;#[pin_project]structStruct<T,U>{#[pin]pinned:T,unpinned:U,}impl<T,U>Struct<T,U>{fnmethod(self:Pin<&mutSelf>){let this =self.project();let _:Pin<&mutT> = this.pinned;// Pinned reference to the fieldlet _:&mutU = this.unpinned;// Normal reference to the field}}

code like this will be generated

To use#[pin_project] on enums, you need to name the projection typereturned from the method.

use std::pin::Pin;use pin_project::pin_project;#[pin_project(project =EnumProj)]enumEnum<T,U>{Pinned(#[pin]T),Unpinned(U),}impl<T,U>Enum<T,U>{fnmethod(self:Pin<&mutSelf>){matchself.project(){EnumProj::Pinned(x) =>{let _:Pin<&mutT> = x;}EnumProj::Unpinned(y) =>{let _:&mutU = y;}}}}

code like this will be generated

See#[pin_project] attribute for more details, andseeexamples directory for more examples and generated code.

Related Projects

  • pin-project-lite: A lightweight version of pin-project written with declarative macros.

License

Licensed under either ofApache License, Version 2.0 orMIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shallbe dual licensed as above, without any additional terms or conditions.

About

A crate for safe and ergonomic pin-projection.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp