CodeSampleX

サンプル

http 1.4.0: http::Uri

検証済みサンプル — cargo http 1.4.0: http::Uri. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: Uri::from_str parses full HTTPS URIs exposing scheme…

sha256:466dfb1562d6a5203b6b5969fff199f4510e0720f5eb1db68772871104e8721e

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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::Uri in pkg:cargo/http@1.4.0
パッケージ
シンボル
  • http::Uri
作成日
2026-11-17T02:36:30Z

コントラクト

  1. Uri::from_str parses full HTTPS URIs exposing scheme, authority, host, port_u16, path, query, and path_and_query
  2. Uri::from_static constructs compile-time static URIs without runtime error
  3. Uri::builder assembles scheme, authority, and path_and_query into a serialized Uri equal to its parsed form
  4. Uri::into_parts and Uri::from_parts decompose and reconstruct modified URIs
  5. Uri supports Default::default root path, origin-form relative paths, and asterisk-form targets
  6. Parsing empty or whitespace-containing strings and building scheme-without-authority URIs return Err

ファイル

  • 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-uri"
version = "1.0.0"
dependencies = [
 "http",
]
Cargo.toml
[package]
name = "sample-http-uri"
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::Uri 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::Uri

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:45c1f6598897a816d85dc525bf050d7dd21339fcd3400edac6ea503f29b74aa1","contract":["Uri::from_str parses full HTTPS URIs exposing scheme, authority, host, port_u16, path, query, and path_and_query","Uri::from_static constructs compile-time static URIs without runtime error","Uri::builder assembles scheme, authority, and path_and_query into a serialized Uri equal to its parsed form","Uri::into_parts and Uri::from_parts decompose and reconstruct modified URIs","Uri supports Default::default root path, origin-form relative paths, and asterisk-form targets","Parsing empty or whitespace-containing strings and building scheme-without-authority URIs return Err"],"goal":"verify http::Uri in pkg:cargo/http@1.4.0","kind":"HOW","packages":["pkg:cargo/http@1.4.0"],"schemaVersion":1,"symbols":["http::Uri"]},"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::Uri"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify http::Uri in pkg:cargo/http@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/http@1.4.0"
  ],
  "symbols": [
    "http::Uri"
  ]
}
src/lib.rs
//! Clean-room verification sample for http::Uri.

pub use http::Uri;
test/contract.rs
use http::uri::{PathAndQuery, Scheme};
use http::Uri;

fn main() {
    // 1. Parse full URI and inspect scheme, authority, host, port, path, and query
    let parsed: Uri = "https://example.com:8443/v1/items?limit=10&sort=asc"
        .parse()
        .expect("valid full URI should parse");
    assert_eq!(parsed.scheme(), Some(&Scheme::HTTPS));
    assert_eq!(parsed.scheme_str(), Some("https"));
    assert_eq!(
        parsed.authority().map(|a| a.as_str()),
        Some("example.com:8443")
    );
    assert_eq!(parsed.host(), Some("example.com"));
    assert_eq!(parsed.port_u16(), Some(8443));
    assert_eq!(parsed.path(), "/v1/items");
    assert_eq!(parsed.query(), Some("limit=10&sort=asc"));
    assert_eq!(
        parsed.path_and_query().map(|pq| pq.as_str()),
        Some("/v1/items?limit=10&sort=asc")
    );

    // 2. Construct Uri::from_static without runtime error
    let static_uri = Uri::from_static("http://localhost:8080/health");
    assert_eq!(static_uri.scheme(), Some(&Scheme::HTTP));
    assert_eq!(static_uri.host(), Some("localhost"));
    assert_eq!(static_uri.port_u16(), Some(8080));
    assert_eq!(static_uri.path(), "/health");
    assert_eq!(static_uri.query(), None);

    // 3. Build a URI via Uri::builder() and verify serialization and equality
    let built = Uri::builder()
        .scheme("http")
        .authority("localhost:8080")
        .path_and_query("/health?ready=1")
        .build()
        .expect("builder with valid parts should succeed");
    assert_eq!(built.to_string(), "http://localhost:8080/health?ready=1");
    let reparsed: Uri = built.to_string().parse().expect("serialized URI parses");
    assert_eq!(built, reparsed);

    // 4. Decompose into Parts and reconstruct via Uri::from_parts
    let mut parts = built.into_parts();
    assert_eq!(parts.scheme, Some(Scheme::HTTP));
    parts.path_and_query = Some(PathAndQuery::from_static("/status?ok=true"));
    let rebuilt = Uri::from_parts(parts).expect("rebuilding from valid parts succeeds");
    assert_eq!(rebuilt.to_string(), "http://localhost:8080/status?ok=true");
    assert_eq!(rebuilt.path(), "/status");
    assert_eq!(rebuilt.query(), Some("ok=true"));

    // 5. Origin-form, asterisk-form, and Default::default() behavior
    let default_uri = Uri::default();
    assert_eq!(default_uri.path(), "/");
    assert!(default_uri.scheme().is_none());
    assert!(default_uri.authority().is_none());

    let origin: Uri = "/only/path?x=1".parse().expect("origin-form URI parses");
    assert!(origin.scheme().is_none());
    assert!(origin.authority().is_none());
    assert_eq!(origin.path(), "/only/path");
    assert_eq!(origin.query(), Some("x=1"));

    let asterisk = Uri::from_static("*");
    assert_eq!(asterisk.path(), "*");
    assert!(asterisk.scheme().is_none());

    // 6. Reject malformed URIs and inconsistent URI parts
    assert!("".parse::<Uri>().is_err());
    assert!("http://example.com/has space".parse::<Uri>().is_err());
    let missing_authority_with_scheme = Uri::builder()
        .scheme("https")
        .path_and_query("/orphan")
        .build();
    assert!(missing_authority_with_scheme.is_err());

    println!("All http::Uri contract assertions passed.");
}

オリジンシーダー

匿名