Beispiel
pin-project-lite 0.2.18
Verifiziertes Beispiel für cargo pin-project-lite 0.2.18. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand.
sha256:53252a6672f168915673e2250bea42885a6463279ec9ecc76d753f9ae4b7e7a1
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux x64 cargo
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-11-23 |
Fall
HOW- Ziel
- verify pkg:cargo/pin-project-lite@0.2.18
- Pakete
- Erstellt
- 2026-11-23T17:11:48Z
Contract
- pin_project! struct project() and project_ref() return Pin<&mut T>/Pin<&T> for #[pin] fields and &mut U/&U for unpinned fields across repeated Pin::as_mut() reborrows
- pin_project! enum with #[project = ...] and #[project_ref = ...] projects both struct variants with #[pin] fields and unit variants
- pin_project! #[project_replace = ...] replaces a pinned struct in place, dropping the previous pinned field before returning moved-out unpinned fields
- pin_project! impl PinnedDrop executes drop(this: Pin<&mut Self>) exactly once on drop and #[project(!Unpin)] prevents Unpin even when all fields are Unpin
- pin_project! supports both generic ?Sized structs and always-unsized structs with #[pin] slice fields under the 0.2.18 ?Sized Drop check
Dateien
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Quelltext
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "pin-project-lite"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752"
[[package]]
name = "sample-pin-project-lite"
version = "0.1.0"
dependencies = [
"pin-project-lite",
]
[package]
name = "sample-pin-project-lite"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "contract"
path = "test/contract.rs"
[dependencies]
pin-project-lite = "=0.2.18"
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:cargo/pin-project-lite@0.2.18
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/pin-project-lite@0.2.18
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:6419cc7e62ad36e17c94736e72bdb494c359519f977487b2167624b4b62c0ba3","contract":["pin_project! struct project() and project_ref() return Pin\u003c\u0026mut T\u003e/Pin\u003c\u0026T\u003e for #[pin] fields and \u0026mut U/\u0026U for unpinned fields across repeated Pin::as_mut() reborrows","pin_project! enum with #[project = ...] and #[project_ref = ...] projects both struct variants with #[pin] fields and unit variants","pin_project! #[project_replace = ...] replaces a pinned struct in place, dropping the previous pinned field before returning moved-out unpinned fields","pin_project! impl PinnedDrop executes drop(this: Pin\u003c\u0026mut Self\u003e) exactly once on drop and #[project(!Unpin)] prevents Unpin even when all fields are Unpin","pin_project! supports both generic ?Sized structs and always-unsized structs with #[pin] slice fields under the 0.2.18 ?Sized Drop check"],"goal":"verify pkg:cargo/pin-project-lite@0.2.18","kind":"HOW","packages":["pkg:cargo/pin-project-lite@0.2.18"],"schemaVersion":1},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/pin-project-lite@0.2.18"],"schemaVersion":1,"subject":"pkg:cargo/pin-project-lite@0.2.18","verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify pkg:cargo/pin-project-lite@0.2.18",
"kind": "HOW",
"packages": [
"pkg:cargo/pin-project-lite@0.2.18"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
use std::cell::Cell;
use std::pin::Pin;
use pin_project_lite::pin_project;
pin_project! {
pub struct Tracked<T, U> {
#[pin]
pub pinned: T,
pub unpinned: U,
}
}
impl<T, U> Tracked<T, U> {
pub fn update_both(mut self: Pin<&mut Self>, f_pinned: impl FnOnce(Pin<&mut T>), next_unpinned: U) {
let first = self.as_mut().project();
f_pinned(first.pinned);
let second = self.project();
*second.unpinned = next_unpinned;
}
pub fn inspect(self: Pin<&Self>) -> (Pin<&T>, &U) {
let proj = self.project_ref();
(proj.pinned, proj.unpinned)
}
}
pin_project! {
#[project = StageProj]
#[project_ref = StageProjRef]
pub enum Stage<T, U> {
Active {
#[pin]
state: T,
count: U,
},
Done,
}
}
impl<T, U: Copy> Stage<T, U> {
pub fn step(self: Pin<&mut Self>, mutate_state: impl FnOnce(Pin<&mut T>), next_count: U) -> bool {
match self.project() {
StageProj::Active { state, count } => {
mutate_state(state);
*count = next_count;
true
}
StageProj::Done => false,
}
}
pub fn read_count(self: Pin<&Self>) -> Option<U> {
match self.project_ref() {
StageProjRef::Active { state: _, count } => Some(*count),
StageProjRef::Done => None,
}
}
}
pin_project! {
#[project_replace = ReplaceableOwn]
pub struct Replaceable<T, U> {
#[pin]
pub pinned: T,
pub unpinned: U,
}
}
impl<T, U> Replaceable<T, U> {
pub fn swap_with(self: Pin<&mut Self>, replacement: Self) -> U {
let old: ReplaceableOwn<T, U> = self.project_replace(replacement);
old.unpinned
}
}
pin_project! {
#[project(!Unpin)]
pub struct Guarded<'a, T> {
#[pin]
pub value: T,
pub drops: &'a Cell<usize>,
}
impl<T> PinnedDrop for Guarded<'_, T> {
fn drop(this: Pin<&mut Self>) {
let proj = this.project();
proj.drops.set(proj.drops.get() + 1);
}
}
}
impl<T> Guarded<'_, T> {
pub fn read_value(self: Pin<&Self>) -> Pin<&T> {
self.project_ref().value
}
}
pin_project! {
pub struct UnsizedFrame<T: ?Sized> {
pub header: u32,
#[pin]
pub payload: T,
}
}
impl UnsizedFrame<[u8]> {
pub fn bump_and_sum(self: Pin<&mut Self>) -> (u32, u16) {
let proj = self.project();
*proj.header += 1;
let slice: &mut [u8] = proj.payload.get_mut();
for b in slice.iter_mut() {
*b += 1;
}
let sum: u16 = slice.iter().map(|&b| u16::from(b)).sum();
(*proj.header, sum)
}
pub fn header_and_len(self: Pin<&Self>) -> (u32, usize) {
let proj = self.project_ref();
(*proj.header, proj.payload.get_ref().len())
}
}
pin_project! {
#[repr(transparent)]
pub struct AlwaysUnsized {
#[pin]
tail: [u8],
}
}
impl AlwaysUnsized {
pub fn from_mut(slice: &mut [u8]) -> &mut Self {
// SAFETY: AlwaysUnsized is #[repr(transparent)] over [u8].
unsafe { &mut *(slice as *mut [u8] as *mut Self) }
}
pub fn xor_all(self: Pin<&mut Self>, mask: u8) {
let proj = self.project();
for b in proj.tail.get_mut().iter_mut() {
*b ^= mask;
}
}
pub fn as_bytes(self: Pin<&Self>) -> &[u8] {
self.project_ref().tail.get_ref()
}
}
use std::cell::Cell;
use std::marker::{PhantomData, PhantomPinned};
use std::pin::Pin;
use sample_pin_project_lite::{AlwaysUnsized, Guarded, Replaceable, Stage, Tracked, UnsizedFrame};
struct DropProbe<'a> {
drops: &'a Cell<usize>,
id: u32,
_pin: PhantomPinned,
}
impl Drop for DropProbe<'_> {
fn drop(&mut self) {
self.drops.set(self.drops.get() + 1);
}
}
trait FallbackNotUnpin {
const IS_UNPIN: bool = false;
}
struct UnpinCheck<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> FallbackNotUnpin for UnpinCheck<T> {}
impl<T: ?Sized + Unpin> UnpinCheck<T> {
const IS_UNPIN: bool = true;
}
fn main() {
// 1. Struct projection: project() with Pin::as_mut() reborrows and project_ref()
assert!(UnpinCheck::<Tracked<u32, String>>::IS_UNPIN);
assert!(!UnpinCheck::<Tracked<PhantomPinned, u32>>::IS_UNPIN);
assert!(!UnpinCheck::<Guarded<'_, u32>>::IS_UNPIN);
let mut tracked = Box::pin(Tracked {
pinned: Cell::new(10u32),
unpinned: String::from("init"),
});
tracked.as_mut().update_both(
|p| p.as_ref().get_ref().set(p.get() + 5),
String::from("updated"),
);
let (pinned_ref, unpinned_ref) = tracked.as_ref().inspect();
assert_eq!(pinned_ref.get_ref().get(), 15);
assert_eq!(unpinned_ref, "updated");
// 2. Enum projection: #[project = ...] and #[project_ref = ...] on struct & unit variants
let mut active = Box::pin(Stage::Active {
state: Cell::new(1u8),
count: 0u32,
});
assert!(active
.as_mut()
.step(|s| s.as_ref().get_ref().set(s.get() + 2), 7));
assert_eq!(active.as_ref().read_count(), Some(7));
let mut done: Pin<Box<Stage<Cell<u8>, u32>>> = Box::pin(Stage::Done);
assert!(!done.as_mut().step(|_| {}, 99));
assert_eq!(done.as_ref().read_count(), None);
// 3. #[project_replace = ...]: replaces pinned value in place, dropping old pinned field
let probe_drops = Cell::new(0usize);
{
let mut replaceable = Box::pin(Replaceable {
pinned: DropProbe {
drops: &probe_drops,
id: 1,
_pin: PhantomPinned,
},
unpinned: String::from("first"),
});
assert_eq!(probe_drops.get(), 0);
let moved_out = replaceable.as_mut().swap_with(Replaceable {
pinned: DropProbe {
drops: &probe_drops,
id: 2,
_pin: PhantomPinned,
},
unpinned: String::from("second"),
});
assert_eq!(moved_out, "first");
assert_eq!(probe_drops.get(), 1);
assert_eq!(replaceable.as_ref().pinned.id, 2);
assert_eq!(replaceable.as_ref().unpinned, "second");
}
assert_eq!(probe_drops.get(), 2);
// 4. impl PinnedDrop + #[project(!Unpin)]
let guarded_drops = Cell::new(0usize);
{
let guarded = Box::pin(Guarded {
value: 42u32,
drops: &guarded_drops,
});
assert_eq!(*guarded.as_ref().read_value().get_ref(), 42);
assert_eq!(guarded_drops.get(), 0);
}
assert_eq!(guarded_drops.get(), 1);
// 5. Unsized generic struct and always-unsized struct (exercises 0.2.18 ?Sized Drop check)
let mut frame: Pin<Box<UnsizedFrame<[u8]>>> = Box::pin(UnsizedFrame {
header: 10,
payload: [1u8, 2, 3, 4],
});
assert_eq!(frame.as_ref().header_and_len(), (10, 4));
assert_eq!(frame.as_mut().bump_and_sum(), (11, 14));
let mut bytes = [0x0Fu8, 0xF0, 0xAA];
{
let mut always_unsized = Pin::new(AlwaysUnsized::from_mut(&mut bytes));
always_unsized.as_mut().xor_all(0xFF);
assert_eq!(always_unsized.as_ref().as_bytes(), &[0xF0, 0x0F, 0x55]);
}
assert_eq!(bytes, [0xF0, 0x0F, 0x55]);
}
Ursprungs-Seeder
anonym