CodeSampleX

示例

typenum 1.20.1: typenum::op

已验证示例 — cargo typenum 1.20.1: typenum::op. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: typenum::op!(U3 + U4 * U2) evaluates with operator…

sha256:6d0b7f219ca8bdcd53976b44562c6f3651cde5ca1b1873f12a78ab569637b4cb

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-10-22

案例

HOW
目标
verify typenum::op in pkg:cargo/typenum@1.20.1
包
符号
  • typenum::op
创建时间
2026-10-22T17:22:26Z

契约

  1. typenum::op!(U3 + U4 * U2) evaluates with operator precedence to U11 (USIZE == 11)
  2. typenum::op!((U11 / U4) + (U11 % U4)) evaluates unsigned division and remainder to U5 (USIZE == 5)
  3. typenum::op!((U5 << U1) | U1) and typenum::op!((U7 & U3) + (U5 ^ U3)) evaluate type-level bitwise shift, OR, AND, and XOR operations
  4. typenum::op!(P5 + N2), typenum::op!(N3 * N2 * (P5 + N3)), and typenum::op!(P3 + N3) evaluate signed integer arithmetic to P3, P12, and Z0
  5. typenum::op!(U5 == U5), typenum::op!(U3 < U5), and typenum::op!(U3 > U5) evaluate type-level comparisons to B1 and B0

文件

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs

下载源代码构件 (tar.gz)

源代码

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "sample-typenum-op"
version = "0.1.0"
dependencies = [
 "typenum",
]

[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
Cargo.toml
[package]
name = "sample-typenum-op"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
typenum = "=1.20.1"
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 typenum::op in pkg:cargo/typenum@1.20.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/typenum@1.20.1
Demonstrate these symbols/APIs:
  - typenum::op

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:f18c24c41055b9c721a5d408a5dbfe95ecc7d2e1aadf1b9007e6fcc08aa2d334","contract":["typenum::op!(U3 + U4 * U2) evaluates with operator precedence to U11 (USIZE == 11)","typenum::op!((U11 / U4) + (U11 % U4)) evaluates unsigned division and remainder to U5 (USIZE == 5)","typenum::op!((U5 \u003c\u003c U1) | U1) and typenum::op!((U7 \u0026 U3) + (U5 ^ U3)) evaluate type-level bitwise shift, OR, AND, and XOR operations","typenum::op!(P5 + N2), typenum::op!(N3 * N2 * (P5 + N3)), and typenum::op!(P3 + N3) evaluate signed integer arithmetic to P3, P12, and Z0","typenum::op!(U5 == U5), typenum::op!(U3 \u003c U5), and typenum::op!(U3 \u003e U5) evaluate type-level comparisons to B1 and B0"],"goal":"verify typenum::op in pkg:cargo/typenum@1.20.1","kind":"HOW","packages":["pkg:cargo/typenum@1.20.1"],"schemaVersion":1,"symbols":["typenum::op"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/typenum@1.20.1"],"schemaVersion":1,"subject":"pkg:cargo/typenum@1.20.1","symbols":["typenum::op"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify typenum::op in pkg:cargo/typenum@1.20.1",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/typenum@1.20.1"
  ],
  "symbols": [
    "typenum::op"
  ]
}
src/main.rs
use typenum::{
    assert_type_eq, op, Bit, Integer, Unsigned, B0, B1, N2, N3, P12, P3, P5, U1, U11, U2, U3, U4,
    U5, U6, U7, Z0,
};

fn main() {
    // Unsigned arithmetic precedence: multiplication and division/remainder before addition/subtraction
    type ArithResult = typenum::op!(U3 + U4 * U2);
    assert_type_eq!(ArithResult, U11);
    assert_eq!(ArithResult::USIZE, 11);

    type DivRemResult = op!((U11 / U4) + (U11 % U4));
    assert_type_eq!(DivRemResult, U5);
    assert_eq!(DivRemResult::USIZE, 5);

    // Bitwise shifts and boolean/masking operations on unsigned integers
    type ShiftOrResult = op!((U5 << U1) | U1);
    assert_type_eq!(ShiftOrResult, U11);
    assert_eq!(ShiftOrResult::USIZE, 11);

    type BitwiseAndXor = op!((U7 & U3) + (U5 ^ U3));
    assert_type_eq!(BitwiseAndXor, op!(U3 + U6));
    assert_eq!(BitwiseAndXor::USIZE, 9);

    // Signed integer arithmetic (Pos, Neg, Z0)
    type SignedSum = op!(P5 + N2);
    assert_type_eq!(SignedSum, P3);
    assert_eq!(SignedSum::I32, 3);

    type SignedProduct = op!(N3 * N2 * (P5 + N3));
    assert_type_eq!(SignedProduct, P12);
    assert_eq!(SignedProduct::I32, 12);

    type SignedZero = op!(P3 + N3);
    assert_type_eq!(SignedZero, Z0);
    assert_eq!(SignedZero::I32, 0);

    // Type-level comparison operators returning Bit (B1 / B0)
    type CmpEq = op!(U5 == U5);
    type CmpLt = op!(U3 < U5);
    type CmpGtFalse = op!(U3 > U5);
    assert_type_eq!(CmpEq, B1);
    assert_type_eq!(CmpLt, B1);
    assert_type_eq!(CmpGtFalse, B0);
    assert!(CmpEq::BOOL);
    assert!(CmpLt::BOOL);
    assert!(!CmpGtFalse::BOOL);
}

原始种子者

匿名