Exemplo
tower-layer 0.3.3: Show that `tower-layer` reference-based stacking can share hidden mutable state across wraps.
Amostra verificada para cargo tower-layer 0.3.3: Show that `tower-layer` reference-based stacking can share hidden mutable state across wraps. O contrato…
sha256:67aad743bfcda22dbbef71bd3cc7a9cbf0de2d864ae984e0560355f976360ace
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 3
- Chaves de assinatura que o compilaram
- 3
Ambiente declarado
rust linux x64 rust rust cargo
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-17 |
| rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-18 |
| 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-08 |
Caso
HOW- Objetivo
- Show that `tower-layer` reference-based stacking can share hidden mutable state across wraps.
- Pacotes
- Símbolos
-
- tower_layer::Layer
- Ambiente
- rust
- Criado
- 2026-08-17T01:08:09Z
Contrato
- assert that the same borrowed layer can be used for multiple `Layer::layer` calls and the call count is cumulative
- assert that wrapped services reflect distinct build IDs because the shared reference updates shared state
- assert that this shared mutable behavior is observable even though the trait method takes `&self`
Arquivos
- Cargo.lock
- Cargo.toml
- NOTES.md
- csx.json
- src/lib.rs
Código-fonte
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
[[package]]
name = "tower-layer-version-trap"
version = "0.1.0"
dependencies = [
"tower-layer",
]
[package]
name = "tower-layer-version-trap"
version = "0.1.0"
edition = "2021"
[dependencies]
tower-layer = "0.3.3"
Search hit used: sample `sha256:70cb8cec09e074888556da7097e94d68ad979b471ca30473f3e2662c391dd7fd` (ServiceBuilder layering/order and timeout/load-shed/retry behavior), so this sample uses a different trap: shared state from borrowed `&Layer` usages.
In a pre-`0.3.1` `tower-layer`, the borrowed `&Layer` call fails to compile at type-check time (`&T` does not implement `Layer`), while `0.3.3` compiles and accumulates shared state across wraps.
{"case":{"believed":"A competent developer would expect a shared `\u0026Layer` to behave like independent applications and not accumulate per-wrap side effects when reused.","caseId":"case:sha256:5d64a65cc29fabbb7950228ab78bcde9443f7e5ee71d09ed358b9013a29da803","contract":["assert that the same borrowed layer can be used for multiple `Layer::layer` calls and the call count is cumulative","assert that wrapped services reflect distinct build IDs because the shared reference updates shared state","assert that this shared mutable behavior is observable even though the trait method takes `\u0026self`"],"goal":"Show that `tower-layer` reference-based stacking can share hidden mutable state across wraps.","kind":"HOW","packages":["pkg:cargo/tower-layer@0.3.3"],"schemaVersion":1,"symbols":["tower_layer::Layer"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/tower-layer@0.3.3"],"schemaVersion":1,"symbols":["tower_layer::Layer"],"verifierAdapter":"cargo@1"}
use std::cell::Cell;
use std::rc::Rc;
use tower_layer::Layer;
#[derive(Clone)]
struct SharedCounterLayer {
calls: Rc<Cell<usize>>,
}
impl SharedCounterLayer {
fn new() -> Self {
Self {
calls: Rc::new(Cell::new(0)),
}
}
}
#[derive(Clone, Debug)]
struct WrappedService<T> {
inner: T,
build_id: usize,
}
impl<T> WrappedService<T> {
fn build_id(&self) -> usize {
self.build_id
}
}
impl<T> Layer<T> for SharedCounterLayer {
type Service = WrappedService<T>;
fn layer(&self, inner: T) -> Self::Service {
let build_id = self.calls.get() + 1;
self.calls.set(build_id);
WrappedService {
inner,
build_id,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn shared_reference_layering_reuses_state() {
let layer = SharedCounterLayer::new();
let layer_ref = &layer;
let first = layer_ref.layer("alpha");
let second = layer_ref.layer("bravo");
assert_eq!(layer.calls.get(), 2);
assert_eq!(first.build_id(), 1);
assert_eq!(second.build_id(), 2);
assert_ne!(first.build_id(), second.build_id());
let third = (&layer).layer("charlie");
assert_eq!(third.build_id(), 3);
assert_eq!(layer.calls.get(), 3);
}
}