Пример
allocator-api2 0.2.21: allocator_api2::alloc::Allocator
Проверенный пример — cargo allocator-api2 0.2.21: allocator_api2::alloc::Allocator. Контракт выполнен на rust 1 · linux alpine/x64 · docker и пройден.
sha256:c8607273cca682390e38f0d3b2ad5917abd1bb5552f20b1b0e5fb5a7cdbe2470
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux x64 cargo
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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-05 |
Кейс
HOW- Цель
- verify allocator_api2::alloc::Allocator in pkg:cargo/allocator-api2@0.2.21
- Пакеты
- Символы
-
- allocator_api2::alloc::Allocator
- Создан
- 2026-11-05T21:28:59Z
Контракт
- Allocator::allocate_zeroed(layout) returns NonNull<[u8]> of at least layout.size() zero-initialized bytes
- Allocator::grow and Allocator::shrink resize an allocated block while preserving existing prefix bytes
- Allocator::deallocate frees memory allocated or resized by the same allocator
- Allocator::by_ref borrows the allocator for use with Box::new_in and Vec::with_capacity_in
Файлы
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/main.rs
Исходный код
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "allocator-api2"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "sample-allocator-api2"
version = "0.1.0"
dependencies = [
"allocator-api2",
]
[package]
name = "sample-allocator-api2"
version = "0.1.0"
edition = "2021"
[dependencies]
allocator-api2 = "=0.2.21"
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 allocator_api2::alloc::Allocator in pkg:cargo/allocator-api2@0.2.21
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/allocator-api2@0.2.21
Demonstrate these symbols/APIs:
- allocator_api2::alloc::Allocator
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:8ac139117db5c76cbf3d73719a71d2c5734b65240f67f3dd00719a762713b8b7","contract":["Allocator::allocate_zeroed(layout) returns NonNull\u003c[u8]\u003e of at least layout.size() zero-initialized bytes","Allocator::grow and Allocator::shrink resize an allocated block while preserving existing prefix bytes","Allocator::deallocate frees memory allocated or resized by the same allocator","Allocator::by_ref borrows the allocator for use with Box::new_in and Vec::with_capacity_in"],"goal":"verify allocator_api2::alloc::Allocator in pkg:cargo/allocator-api2@0.2.21","kind":"HOW","packages":["pkg:cargo/allocator-api2@0.2.21"],"schemaVersion":1,"symbols":["allocator_api2::alloc::Allocator"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/allocator-api2@0.2.21"],"schemaVersion":1,"subject":"pkg:cargo/allocator-api2@0.2.21","symbols":["allocator_api2::alloc::Allocator"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify allocator_api2::alloc::Allocator in pkg:cargo/allocator-api2@0.2.21",
"kind": "HOW",
"packages": [
"pkg:cargo/allocator-api2@0.2.21"
],
"symbols": [
"allocator_api2::alloc::Allocator"
]
}
use std::alloc::Layout;
use allocator_api2::alloc::{Allocator, Global};
use allocator_api2::boxed::Box;
use allocator_api2::vec::Vec;
fn allocate_and_fill<A: Allocator>(alloc: &A, count: usize, value: u8) -> Vec<u8, &A> {
let mut vec = Vec::with_capacity_in(count, alloc.by_ref());
vec.resize(count, value);
vec
}
fn main() {
let global = Global;
// 1. Direct allocation and deallocation via the Allocator trait
let layout = Layout::from_size_align(64, 8).expect("valid layout");
let ptr = global.allocate_zeroed(layout).expect("allocation succeeds");
assert_eq!(ptr.len(), 64);
let slice: &[u8] = unsafe { ptr.as_ref() };
assert!(slice.iter().all(|&b| b == 0));
unsafe {
global.deallocate(ptr.cast::<u8>(), layout);
}
// 2. Grow and shrink via the Allocator trait
let initial_layout = Layout::from_size_align(16, 8).expect("valid layout");
let grown_layout = Layout::from_size_align(32, 8).expect("valid layout");
let shrunk_layout = Layout::from_size_align(8, 8).expect("valid layout");
let block = global.allocate(initial_layout).expect("initial alloc");
unsafe {
std::ptr::write_bytes(block.cast::<u8>().as_ptr(), 0xAB, 16);
let grown = global
.grow(block.cast::<u8>(), initial_layout, grown_layout)
.expect("grow succeeds");
assert!(grown.len() >= 32);
let grown_bytes = grown.as_ref();
assert!(grown_bytes[..16].iter().all(|&b| b == 0xAB));
let shrunk = global
.shrink(grown.cast::<u8>(), grown_layout, shrunk_layout)
.expect("shrink succeeds");
assert!(shrunk.len() >= 8);
assert!(shrunk.as_ref()[..8].iter().all(|&b| b == 0xAB));
global.deallocate(shrunk.cast::<u8>(), shrunk_layout);
}
// 3. Using Allocator with Box and Vec via generic bound and by_ref
let boxed = Box::new_in(42_u64, &global);
assert_eq!(*boxed, 42);
let vec = allocate_and_fill(&global, 4, 7);
assert_eq!(vec.as_slice(), &[7, 7, 7, 7]);
}
Исходный сидер
аноним