CodeSampleX

Sample

pin-project-lite 0.2.18

Verified sample for cargo pin-project-lite 0.2.18. The contract ran on rust 1 · linux alpine/x64 · docker and passed: pin_project! struct project() and…

sha256:53252a6672f168915673e2250bea42885a6463279ec9ecc76d753f9ae4b7e7a1

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux x64 cargo

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:cargo/pin-project-lite@0.2.18
Packages
Created
2026-11-23T17:11:48Z

Contract

  1. 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
  2. pin_project! enum with #[project = ...] and #[project_ref = ...] projects both struct variants with #[pin] fields and unit variants
  3. pin_project! #[project_replace = ...] replaces a pinned struct in place, dropping the previous pinned field before returning moved-out unpinned fields
  4. 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
  5. pin_project! supports both generic ?Sized structs and always-unsized structs with #[pin] slice fields under the 0.2.18 ?Sized Drop check

Files

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Download the source artifact (tar.gz)

Source

Cargo.lock
# 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",
]
Cargo.toml
[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"
PROMPT.md
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.
csx.json
{"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"}
spec.json
{
  "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"
  }
}
src/lib.rs
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()
    }
}
test/contract.rs
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]);
}

Origin Seeder

anonymous