CodeSampleX

Beispiel

serde_urlencoded 0.7.1: serde_urlencoded::from_str, serde_urlencoded::to_string

Verifiziertes Beispiel für cargo serde_urlencoded 0.7.1: serde_urlencoded::from_str, serde_urlencoded::to_string. Der Vertrag lief auf rust 1 · linux…

sha256:9a34876ce97d62f759ace2d6d3acbe4a6163cc2bb7e048d742f23eb1ace138e9

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux · alpine · musl x64 cargo

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-09-19

Fall

HOW
Ziel
verify pkg:cargo/serde_urlencoded@0.7.1
Pakete
Symbole
  • serde_urlencoded::from_str
  • serde_urlencoded::to_string
Erstellt
2026-09-18T13:04:54Z

Contract

  1. to_string serializes sequence of key-value pairs to URL-encoded query string
  2. to_string percent-encodes special characters and spaces
  3. from_str deserializes URL-encoded query string into sequence of key-value pairs
  4. from_str decodes percent-encoded characters and plus signs
  5. from_str returns error when value cannot be parsed into target type

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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

[[package]]
name = "form_urlencoded"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
dependencies = [
 "percent-encoding",
]

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

[[package]]
name = "percent-encoding"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"

[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "ryu"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"

[[package]]
name = "sample-serde-urlencoded"
version = "1.0.0"
dependencies = [
 "serde_urlencoded",
]

[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
 "serde_core",
]

[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
 "form_urlencoded",
 "itoa",
 "ryu",
 "serde",
]

[[package]]
name = "syn"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
Cargo.toml
[package]
name = "sample-serde-urlencoded"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
serde_urlencoded = "=0.7.1"

[[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 pkg:cargo/serde_urlencoded@0.7.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/serde_urlencoded@0.7.1
Demonstrate these symbols/APIs:
  - serde_urlencoded::from_str
  - serde_urlencoded::to_string

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:c1118fb1af7658528e8f14e268068e22fbf2ae6cd3861fc1069b30b129301504","contract":["to_string serializes sequence of key-value pairs to URL-encoded query string","to_string percent-encodes special characters and spaces","from_str deserializes URL-encoded query string into sequence of key-value pairs","from_str decodes percent-encoded characters and plus signs","from_str returns error when value cannot be parsed into target type"],"goal":"verify pkg:cargo/serde_urlencoded@0.7.1","kind":"HOW","packages":["pkg:cargo/serde_urlencoded@0.7.1"],"schemaVersion":1,"symbols":["serde_urlencoded::from_str","serde_urlencoded::to_string"]},"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/serde_urlencoded@0.7.1"],"schemaVersion":1,"subject":"pkg:cargo/serde_urlencoded@0.7.1","symbols":["serde_urlencoded::from_str","serde_urlencoded::to_string"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/serde_urlencoded@0.7.1",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/serde_urlencoded@0.7.1"
  ],
  "symbols": [
    "serde_urlencoded::from_str",
    "serde_urlencoded::to_string"
  ]
}
src/lib.rs
//! Clean-room verification sample for serde_urlencoded.

pub use serde_urlencoded::*;
test/contract.rs
use serde_urlencoded::{from_str, to_string};

fn main() {
    // 1. to_string serializes sequence of key-value pairs to URL-encoded query string
    let params = &[("name", "alice"), ("role", "admin")];
    let encoded = to_string(params).expect("failed to serialize params");
    assert_eq!(encoded, "name=alice&role=admin");

    // 2. to_string percent-encodes special characters and spaces
    let special = &[("query", "hello world!"), ("tag", "a&b=c")];
    let encoded_special = to_string(special).expect("failed to serialize special chars");
    assert_eq!(encoded_special, "query=hello+world%21&tag=a%26b%3Dc");

    // 3. from_str deserializes URL-encoded query string into sequence of key-value pairs
    let input = "user=bob&status=active";
    let decoded: Vec<(String, String)> = from_str(input).expect("failed to deserialize");
    assert_eq!(
        decoded,
        vec![
            ("user".to_string(), "bob".to_string()),
            ("status".to_string(), "active".to_string()),
        ]
    );

    // 4. from_str decodes percent-encoded characters and plus signs
    let encoded_input = "city=New+York&greeting=hello%20world";
    let decoded_special: Vec<(String, String)> =
        from_str(encoded_input).expect("failed to deserialize special");
    assert_eq!(
        decoded_special,
        vec![
            ("city".to_string(), "New York".to_string()),
            ("greeting".to_string(), "hello world".to_string()),
        ]
    );

    // 5. from_str returns error when value cannot be parsed into target type
    let invalid_int = "id=not_an_int";
    let err = from_str::<Vec<(String, u32)>>(invalid_int);
    assert!(err.is_err());

    println!("All serde_urlencoded contract assertions passed successfully.");
}

Ursprungs-Seeder

anonym