CodeSampleX

サンプル

http 1.4.0: http::StatusCode

検証済みサンプル — cargo http 1.4.0: http::StatusCode. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: http::StatusCode standard constants…

sha256:d9e86e5814cc5246ab5781416cb42b3d242f8296244311150f14679333ccad92

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux · alpine · musl 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-17

ケース

HOW
ゴール
verify http::StatusCode in pkg:cargo/http@1.4.0
パッケージ
シンボル
  • http::StatusCode
作成日
2026-11-17T01:45:47Z

コントラクト

  1. http::StatusCode standard constants, StatusCode::default (200 OK), as_u16, as_str, canonical_reason, and Display formatting return the expected numeric code, three-digit string, and reason phrase
  2. http::StatusCode::from_u16, from_bytes, and FromStr construct valid status codes across 100..=999 including unassigned codes where canonical_reason is None
  3. http::StatusCode implements TryFrom<u16>, TryFrom<&str>, TryFrom<&[u8]>, Into<u16>, and PartialEq<u16> for fallible conversion and direct u16 comparison
  4. http::StatusCode::from_u16, from_bytes, and FromStr return Err(InvalidStatusCode) for out-of-range integers (< 100 or >= 1000) and non-three-digit inputs such as "200 OK"
  5. http::StatusCode::is_informational, is_success, is_redirection, is_client_error, and is_server_error classify 1xx through 5xx codes and all return false for 600..=999

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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

[[package]]
name = "bytes"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"

[[package]]
name = "http"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a"
dependencies = [
 "bytes",
 "itoa",
]

[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"

[[package]]
name = "sample-http-status-code"
version = "1.0.0"
dependencies = [
 "http",
]
Cargo.toml
[package]
name = "sample-http-status-code"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
http = "=1.4.0"

[[bin]]
name = "contract"
path = "test/contract.rs"
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 http::StatusCode in pkg:cargo/http@1.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/http@1.4.0
Demonstrate these symbols/APIs:
  - http::StatusCode

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:7d357b87e5e0a9cf88c61ac0c7502bd951c1cea6423131ceb56cc36414f6205c","contract":["http::StatusCode standard constants, StatusCode::default (200 OK), as_u16, as_str, canonical_reason, and Display formatting return the expected numeric code, three-digit string, and reason phrase","http::StatusCode::from_u16, from_bytes, and FromStr construct valid status codes across 100..=999 including unassigned codes where canonical_reason is None","http::StatusCode implements TryFrom\u003cu16\u003e, TryFrom\u003c\u0026str\u003e, TryFrom\u003c\u0026[u8]\u003e, Into\u003cu16\u003e, and PartialEq\u003cu16\u003e for fallible conversion and direct u16 comparison","http::StatusCode::from_u16, from_bytes, and FromStr return Err(InvalidStatusCode) for out-of-range integers (\u003c 100 or \u003e= 1000) and non-three-digit inputs such as \"200 OK\"","http::StatusCode::is_informational, is_success, is_redirection, is_client_error, and is_server_error classify 1xx through 5xx codes and all return false for 600..=999"],"goal":"verify http::StatusCode in pkg:cargo/http@1.4.0","kind":"HOW","packages":["pkg:cargo/http@1.4.0"],"schemaVersion":1,"symbols":["http::StatusCode"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/http@1.4.0"],"schemaVersion":1,"subject":"pkg:cargo/http@1.4.0","symbols":["http::StatusCode"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify http::StatusCode in pkg:cargo/http@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/http@1.4.0"
  ],
  "symbols": [
    "http::StatusCode"
  ]
}
src/lib.rs
//! Clean-room verification sample for http::StatusCode.

pub use http::StatusCode;
test/contract.rs
use http::status::InvalidStatusCode;
use http::StatusCode;
use std::str::FromStr;

fn main() {
    // 1. Standard constants, numeric/string accessors, canonical reasons, and Default
    assert_eq!(StatusCode::default(), StatusCode::OK);
    assert_eq!(StatusCode::OK.as_u16(), 200);
    assert_eq!(StatusCode::OK.as_str(), "200");
    assert_eq!(StatusCode::OK.canonical_reason(), Some("OK"));
    assert_eq!(StatusCode::NOT_FOUND.as_u16(), 404);
    assert_eq!(StatusCode::NOT_FOUND.as_str(), "404");
    assert_eq!(StatusCode::NOT_FOUND.canonical_reason(), Some("Not Found"));
    assert_eq!(
        StatusCode::INTERNAL_SERVER_ERROR.canonical_reason(),
        Some("Internal Server Error")
    );
    assert_eq!(format!("{}", StatusCode::NOT_FOUND), "404 Not Found");

    // 2. Fallible construction from u16, &[u8], and &str within valid range 100..=999
    let min_valid = StatusCode::from_u16(100).expect("100 is valid");
    assert_eq!(min_valid, StatusCode::CONTINUE);

    let custom_299 = StatusCode::from_u16(299).expect("299 is valid");
    assert_eq!(custom_299.as_u16(), 299);
    assert_eq!(custom_299.as_str(), "299");
    assert_eq!(custom_299.canonical_reason(), None);

    let max_valid = StatusCode::from_u16(999).expect("999 is valid");
    assert_eq!(max_valid.as_u16(), 999);
    assert_eq!(max_valid.as_str(), "999");

    assert_eq!(
        StatusCode::from_bytes(b"201").expect("b\"201\" is valid"),
        StatusCode::CREATED
    );
    assert_eq!(
        StatusCode::from_str("204").expect("\"204\" is valid"),
        StatusCode::NO_CONTENT
    );

    // 3. TryFrom<u16>, TryFrom<&str>, TryFrom<&[u8]>, Into<u16>, and PartialEq<u16>
    let via_try_u16 = StatusCode::try_from(418_u16).expect("TryFrom<u16> for 418");
    assert_eq!(via_try_u16, StatusCode::IM_A_TEAPOT);
    assert_eq!(via_try_u16, 418_u16);
    assert_eq!(418_u16, via_try_u16);
    assert_eq!(u16::from(via_try_u16), 418_u16);

    let via_try_str = StatusCode::try_from("301").expect("TryFrom<&str> for \"301\"");
    assert_eq!(via_try_str, StatusCode::MOVED_PERMANENTLY);

    let via_try_bytes = StatusCode::try_from(&b"503"[..]).expect("TryFrom<&[u8]> for b\"503\"");
    assert_eq!(via_try_bytes, StatusCode::SERVICE_UNAVAILABLE);

    // 4. Out-of-range values (< 100 or >= 1000) and malformed byte/string inputs return Err(InvalidStatusCode)
    let err_zero: Result<StatusCode, InvalidStatusCode> = StatusCode::from_u16(0);
    assert!(err_zero.is_err());
    assert!(StatusCode::from_u16(99).is_err());
    assert!(StatusCode::from_u16(1000).is_err());
    assert!(StatusCode::try_from(1000_u16).is_err());

    assert!(StatusCode::from_bytes(b"").is_err());
    assert!(StatusCode::from_bytes(b"99").is_err());
    assert!(StatusCode::from_bytes(b"1000").is_err());
    assert!(StatusCode::from_bytes(b"20A").is_err());
    assert!(StatusCode::from_str("200 OK").is_err());

    // 5. Status class predicates partition 1xx-5xx and return false for 600..=999
    assert!(StatusCode::CONTINUE.is_informational());
    assert!(!StatusCode::CONTINUE.is_success());

    assert!(StatusCode::OK.is_success());
    assert!(custom_299.is_success());
    assert!(!StatusCode::OK.is_redirection());

    assert!(StatusCode::MOVED_PERMANENTLY.is_redirection());
    assert!(!StatusCode::MOVED_PERMANENTLY.is_client_error());

    assert!(StatusCode::BAD_REQUEST.is_client_error());
    assert!(StatusCode::NOT_FOUND.is_client_error());
    assert!(!StatusCode::NOT_FOUND.is_server_error());

    assert!(StatusCode::INTERNAL_SERVER_ERROR.is_server_error());
    assert!(!StatusCode::INTERNAL_SERVER_ERROR.is_client_error());

    let code_600 = StatusCode::from_u16(600).expect("600 is valid");
    assert!(!code_600.is_informational());
    assert!(!code_600.is_success());
    assert!(!code_600.is_redirection());
    assert!(!code_600.is_client_error());
    assert!(!code_600.is_server_error());
}

オリジンシーダー

匿名