pub struct ProverEngine { /* private fields */ }Expand description
High-level proof generation engine.
Uses midnight-ledger’s ZKIR pipeline (v2 + v3 dispatch) to generate proofs for circuits compiled by the Compact compiler.
ProverEngine is Send + Sync and cheap to clone via Arc.
Implementations§
Source§impl ProverEngine
impl ProverEngine
Sourcepub fn new(params: Arc<MidnightDataProvider>) -> Self
pub fn new(params: Arc<MidnightDataProvider>) -> Self
Creates a new ProverEngine with the given data provider.
Concurrent proof slots default to num_cpus.
Sourcepub fn with_concurrency(
params: Arc<MidnightDataProvider>,
max_concurrent: usize,
) -> Self
pub fn with_concurrency( params: Arc<MidnightDataProvider>, max_concurrent: usize, ) -> Self
Creates a ProverEngine with an explicit concurrent-proof
cap. max_concurrent is clamped to at least 1.
Sourcepub fn from_env() -> Result<Self, ProverError>
pub fn from_env() -> Result<Self, ProverError>
Creates a ProverEngine with default settings.
Examples found in repository?
46async fn async_main() {
47 let engine = Arc::new(ProverEngine::from_env().expect("ProverEngine::from_env"));
48 let uncached_params = MidnightDataProvider::new(
49 moonproof_ledger::base_crypto::data_provider::FetchMode::OnDemand,
50 moonproof_ledger::base_crypto::data_provider::OutputMode::Log,
51 Vec::new(),
52 )
53 .expect("MidnightDataProvider");
54
55 // Warm the cached engine once
56 let warm_p = make_zswap_output_preimage(1);
57 let t0 = Instant::now();
58 let _ = engine
59 .prove_preimage(&warm_p, None, None)
60 .await
61 .expect("warm cached");
62 println!(
63 "zswap/output cached cold (first ever): {:.2} ms",
64 t0.elapsed().as_secs_f64() * 1000.0
65 );
66
67 // Interleaved A/B comparison across 5 pairs
68 let pairs = 5usize;
69 let mut uncached_ms = Vec::with_capacity(pairs);
70 let mut cached_ms = Vec::with_capacity(pairs);
71 for i in 0..pairs {
72 let p = make_zswap_output_preimage(100 + i as u64);
73
74 // A: Uncached legacy path (fresh BuiltinResolver + raw MidnightDataProvider + prove_versioned)
75 let ta = Instant::now();
76 let fresh_builtin = BuiltinResolver::new().expect("fresh builtin");
77 let probe = fresh_builtin
78 .resolve_key(p.key_location.clone())
79 .await
80 .expect("resolve")
81 .expect("some");
82 let (proof_a, _) =
83 prove_versioned(&p, &probe.ir_source, None, &uncached_params, &fresh_builtin)
84 .await
85 .expect("uncached prove");
86 let ms_a = ta.elapsed().as_secs_f64() * 1000.0;
87 assert_ne!(proof_a.0.len(), 0);
88 uncached_ms.push(ms_a);
89
90 // B: Optimized cached ProverEngine path
91 let tb = Instant::now();
92 let res_b = engine
93 .prove_preimage(&p, None, None)
94 .await
95 .expect("cached prove");
96 let ms_b = tb.elapsed().as_secs_f64() * 1000.0;
97 assert_ne!(res_b.proof.len(), 0);
98 cached_ms.push(ms_b);
99
100 println!(
101 "pair {}: uncached={ms_a:>7.2} ms cached={ms_b:>7.2} ms speedup={:.2}x",
102 i + 1,
103 ms_a / ms_b
104 );
105 }
106
107 let pairs_f = f64::from(u32::try_from(pairs).expect("pairs fits u32"));
108 let avg_a: f64 = uncached_ms.iter().sum::<f64>() / pairs_f;
109 let avg_b: f64 = cached_ms.iter().sum::<f64>() / pairs_f;
110 let min_a = uncached_ms.iter().copied().fold(f64::INFINITY, f64::min);
111 let min_b = cached_ms.iter().copied().fold(f64::INFINITY, f64::min);
112 println!(
113 "\n=== zswap/output (v1/v2) A/B SUMMARY ===\n uncached: avg={avg_a:.2} ms min={min_a:.2} ms\n cached: avg={avg_b:.2} ms min={min_b:.2} ms\n speedup: {:.2}x avg ({:.2}x min)",
114 avg_a / avg_b,
115 min_a / min_b,
116 );
117
118 // Interleaved A/B for /check
119 let mut check_body = Vec::new();
120 let payload = (
121 moonproof_prover::ProofPreimageVersioned::V2(Arc::new(warm_p.clone())),
122 None::<moonproof_prover::WrappedIr>,
123 );
124 moonproof_prover::tagged_serialize(&payload, &mut check_body).expect("serialize check");
125 let _ = engine.check_payload(&check_body).await.expect("warm check");
126 let t = Instant::now();
127 let n = 20u32;
128 for _ in 0..n {
129 let _ = engine.check_payload(&check_body).await.expect("check");
130 }
131 println!(
132 "zswap/output cached check_payload: {:.2} ms/iter ({n} iters)",
133 t.elapsed().as_secs_f64() * 1000.0 / f64::from(n)
134 );
135}Sourcepub fn params(&self) -> &MidnightDataProvider
pub fn params(&self) -> &MidnightDataProvider
Returns the underlying data provider.
Sourcepub fn builtin_resolver(&self) -> Result<Arc<BuiltinResolver>, ProverError>
pub fn builtin_resolver(&self) -> Result<Arc<BuiltinResolver>, ProverError>
Lazily initialize and return the engine-wide cached BuiltinResolver.
Sourcepub fn stats(&self) -> ProverStats
pub fn stats(&self) -> ProverStats
Snapshot of currently executing and queued proof jobs.
Sourcepub async fn warm_srs(&self, ks: &[u8]) -> Result<(), ProverError>
pub async fn warm_srs(&self, ks: &[u8]) -> Result<(), ProverError>
Pre-load SRS parameters for each k into RAM so subsequent proofs hit
the in-memory cache immediately.
Sourcepub fn parse_zkir(json: &str) -> Result<VersionedIr, ProverError>
pub fn parse_zkir(json: &str) -> Result<VersionedIr, ProverError>
Parses a Compact ZKIR JSON string. Auto-detects v2 vs v3.
Sourcepub fn circuit_k(ir: &VersionedIr) -> u8
pub fn circuit_k(ir: &VersionedIr) -> u8
Determines the circuit size (k) for a given ZKIR.
Sourcepub async fn fetch_srs(&self, k: u8) -> Result<(), ProverError>
pub async fn fetch_srs(&self, k: u8) -> Result<(), ProverError>
Fetches SRS parameters for a given k value (disk/S3) and warms RAM.
Sourcepub async fn prove_preimage(
self: &Arc<Self>,
preimage: &ProofPreimage,
proving_key_material: Option<ProvingKeyMaterial>,
binding_input: Option<Fr>,
) -> Result<ProofResult, ProverError>
pub async fn prove_preimage( self: &Arc<Self>, preimage: &ProofPreimage, proving_key_material: Option<ProvingKeyMaterial>, binding_input: Option<Fr>, ) -> Result<ProofResult, ProverError>
Generates a proof using a ProofPreimage and optional ProvingKeyMaterial.
Examples found in repository?
46async fn async_main() {
47 let engine = Arc::new(ProverEngine::from_env().expect("ProverEngine::from_env"));
48 let uncached_params = MidnightDataProvider::new(
49 moonproof_ledger::base_crypto::data_provider::FetchMode::OnDemand,
50 moonproof_ledger::base_crypto::data_provider::OutputMode::Log,
51 Vec::new(),
52 )
53 .expect("MidnightDataProvider");
54
55 // Warm the cached engine once
56 let warm_p = make_zswap_output_preimage(1);
57 let t0 = Instant::now();
58 let _ = engine
59 .prove_preimage(&warm_p, None, None)
60 .await
61 .expect("warm cached");
62 println!(
63 "zswap/output cached cold (first ever): {:.2} ms",
64 t0.elapsed().as_secs_f64() * 1000.0
65 );
66
67 // Interleaved A/B comparison across 5 pairs
68 let pairs = 5usize;
69 let mut uncached_ms = Vec::with_capacity(pairs);
70 let mut cached_ms = Vec::with_capacity(pairs);
71 for i in 0..pairs {
72 let p = make_zswap_output_preimage(100 + i as u64);
73
74 // A: Uncached legacy path (fresh BuiltinResolver + raw MidnightDataProvider + prove_versioned)
75 let ta = Instant::now();
76 let fresh_builtin = BuiltinResolver::new().expect("fresh builtin");
77 let probe = fresh_builtin
78 .resolve_key(p.key_location.clone())
79 .await
80 .expect("resolve")
81 .expect("some");
82 let (proof_a, _) =
83 prove_versioned(&p, &probe.ir_source, None, &uncached_params, &fresh_builtin)
84 .await
85 .expect("uncached prove");
86 let ms_a = ta.elapsed().as_secs_f64() * 1000.0;
87 assert_ne!(proof_a.0.len(), 0);
88 uncached_ms.push(ms_a);
89
90 // B: Optimized cached ProverEngine path
91 let tb = Instant::now();
92 let res_b = engine
93 .prove_preimage(&p, None, None)
94 .await
95 .expect("cached prove");
96 let ms_b = tb.elapsed().as_secs_f64() * 1000.0;
97 assert_ne!(res_b.proof.len(), 0);
98 cached_ms.push(ms_b);
99
100 println!(
101 "pair {}: uncached={ms_a:>7.2} ms cached={ms_b:>7.2} ms speedup={:.2}x",
102 i + 1,
103 ms_a / ms_b
104 );
105 }
106
107 let pairs_f = f64::from(u32::try_from(pairs).expect("pairs fits u32"));
108 let avg_a: f64 = uncached_ms.iter().sum::<f64>() / pairs_f;
109 let avg_b: f64 = cached_ms.iter().sum::<f64>() / pairs_f;
110 let min_a = uncached_ms.iter().copied().fold(f64::INFINITY, f64::min);
111 let min_b = cached_ms.iter().copied().fold(f64::INFINITY, f64::min);
112 println!(
113 "\n=== zswap/output (v1/v2) A/B SUMMARY ===\n uncached: avg={avg_a:.2} ms min={min_a:.2} ms\n cached: avg={avg_b:.2} ms min={min_b:.2} ms\n speedup: {:.2}x avg ({:.2}x min)",
114 avg_a / avg_b,
115 min_a / min_b,
116 );
117
118 // Interleaved A/B for /check
119 let mut check_body = Vec::new();
120 let payload = (
121 moonproof_prover::ProofPreimageVersioned::V2(Arc::new(warm_p.clone())),
122 None::<moonproof_prover::WrappedIr>,
123 );
124 moonproof_prover::tagged_serialize(&payload, &mut check_body).expect("serialize check");
125 let _ = engine.check_payload(&check_body).await.expect("warm check");
126 let t = Instant::now();
127 let n = 20u32;
128 for _ in 0..n {
129 let _ = engine.check_payload(&check_body).await.expect("check");
130 }
131 println!(
132 "zswap/output cached check_payload: {:.2} ms/iter ({n} iters)",
133 t.elapsed().as_secs_f64() * 1000.0 / f64::from(n)
134 );
135}Sourcepub async fn prove_serialized_preimage(
self: &Arc<Self>,
body: &[u8],
) -> Result<Vec<u8>, ProverError>
pub async fn prove_serialized_preimage( self: &Arc<Self>, body: &[u8], ) -> Result<Vec<u8>, ProverError>
Generate a proof for a tagged-serialized
(ProofPreimageVersioned, Option<ProvingKeyMaterial>, Option<Fr>)
payload — the same wire format the standalone proof-server’s
/prove endpoint accepts.
Sourcepub async fn check_serialized_preimage(
&self,
body: &[u8],
) -> Result<Vec<Option<String>>, ProverError>
pub async fn check_serialized_preimage( &self, body: &[u8], ) -> Result<Vec<Option<String>>, ProverError>
Check a tagged-serialized
(ProofPreimageVersioned, Option<WrappedIr>) payload.
Sourcepub async fn check_payload(
&self,
body: &[u8],
) -> Result<Vec<Option<usize>>, ProverError>
pub async fn check_payload( &self, body: &[u8], ) -> Result<Vec<Option<usize>>, ProverError>
A POST /check request body, checked using cached built-in keys and
cached parsed ZKIR. Offloads constraint checking off Tokio I/O threads
on native targets.
Examples found in repository?
46async fn async_main() {
47 let engine = Arc::new(ProverEngine::from_env().expect("ProverEngine::from_env"));
48 let uncached_params = MidnightDataProvider::new(
49 moonproof_ledger::base_crypto::data_provider::FetchMode::OnDemand,
50 moonproof_ledger::base_crypto::data_provider::OutputMode::Log,
51 Vec::new(),
52 )
53 .expect("MidnightDataProvider");
54
55 // Warm the cached engine once
56 let warm_p = make_zswap_output_preimage(1);
57 let t0 = Instant::now();
58 let _ = engine
59 .prove_preimage(&warm_p, None, None)
60 .await
61 .expect("warm cached");
62 println!(
63 "zswap/output cached cold (first ever): {:.2} ms",
64 t0.elapsed().as_secs_f64() * 1000.0
65 );
66
67 // Interleaved A/B comparison across 5 pairs
68 let pairs = 5usize;
69 let mut uncached_ms = Vec::with_capacity(pairs);
70 let mut cached_ms = Vec::with_capacity(pairs);
71 for i in 0..pairs {
72 let p = make_zswap_output_preimage(100 + i as u64);
73
74 // A: Uncached legacy path (fresh BuiltinResolver + raw MidnightDataProvider + prove_versioned)
75 let ta = Instant::now();
76 let fresh_builtin = BuiltinResolver::new().expect("fresh builtin");
77 let probe = fresh_builtin
78 .resolve_key(p.key_location.clone())
79 .await
80 .expect("resolve")
81 .expect("some");
82 let (proof_a, _) =
83 prove_versioned(&p, &probe.ir_source, None, &uncached_params, &fresh_builtin)
84 .await
85 .expect("uncached prove");
86 let ms_a = ta.elapsed().as_secs_f64() * 1000.0;
87 assert_ne!(proof_a.0.len(), 0);
88 uncached_ms.push(ms_a);
89
90 // B: Optimized cached ProverEngine path
91 let tb = Instant::now();
92 let res_b = engine
93 .prove_preimage(&p, None, None)
94 .await
95 .expect("cached prove");
96 let ms_b = tb.elapsed().as_secs_f64() * 1000.0;
97 assert_ne!(res_b.proof.len(), 0);
98 cached_ms.push(ms_b);
99
100 println!(
101 "pair {}: uncached={ms_a:>7.2} ms cached={ms_b:>7.2} ms speedup={:.2}x",
102 i + 1,
103 ms_a / ms_b
104 );
105 }
106
107 let pairs_f = f64::from(u32::try_from(pairs).expect("pairs fits u32"));
108 let avg_a: f64 = uncached_ms.iter().sum::<f64>() / pairs_f;
109 let avg_b: f64 = cached_ms.iter().sum::<f64>() / pairs_f;
110 let min_a = uncached_ms.iter().copied().fold(f64::INFINITY, f64::min);
111 let min_b = cached_ms.iter().copied().fold(f64::INFINITY, f64::min);
112 println!(
113 "\n=== zswap/output (v1/v2) A/B SUMMARY ===\n uncached: avg={avg_a:.2} ms min={min_a:.2} ms\n cached: avg={avg_b:.2} ms min={min_b:.2} ms\n speedup: {:.2}x avg ({:.2}x min)",
114 avg_a / avg_b,
115 min_a / min_b,
116 );
117
118 // Interleaved A/B for /check
119 let mut check_body = Vec::new();
120 let payload = (
121 moonproof_prover::ProofPreimageVersioned::V2(Arc::new(warm_p.clone())),
122 None::<moonproof_prover::WrappedIr>,
123 );
124 moonproof_prover::tagged_serialize(&payload, &mut check_body).expect("serialize check");
125 let _ = engine.check_payload(&check_body).await.expect("warm check");
126 let t = Instant::now();
127 let n = 20u32;
128 for _ in 0..n {
129 let _ = engine.check_payload(&check_body).await.expect("check");
130 }
131 println!(
132 "zswap/output cached check_payload: {:.2} ms/iter ({n} iters)",
133 t.elapsed().as_secs_f64() * 1000.0 / f64::from(n)
134 );
135}Sourcepub async fn prove_with_optional_keys(
self: &Arc<Self>,
body: &[u8],
key_material: Option<ProvingKeyMaterial>,
binding_input: Option<Fr>,
) -> Result<Vec<u8>, ProverError>
pub async fn prove_with_optional_keys( self: &Arc<Self>, body: &[u8], key_material: Option<ProvingKeyMaterial>, binding_input: Option<Fr>, ) -> Result<Vec<u8>, ProverError>
Like Self::prove_serialized_preimage with out-of-band key material.
Sourcepub async fn check_with_optional_keys(
&self,
body: &[u8],
key_material: Option<ProvingKeyMaterial>,
) -> Result<Vec<Option<String>>, ProverError>
pub async fn check_with_optional_keys( &self, body: &[u8], key_material: Option<ProvingKeyMaterial>, ) -> Result<Vec<Option<String>>, ProverError>
Like Self::check_serialized_preimage with out-of-band key material.
Sourcepub fn parse_and_analyze(json: &str) -> Result<(VersionedIr, u8), ProverError>
pub fn parse_and_analyze(json: &str) -> Result<(VersionedIr, u8), ProverError>
Convenience: parse ZKIR JSON, compute k, and check the circuit.
Sourcepub fn check_preimage(
ir: &VersionedIr,
preimage: &ProofPreimage,
) -> Result<Vec<Option<usize>>, ProverError>
pub fn check_preimage( ir: &VersionedIr, preimage: &ProofPreimage, ) -> Result<Vec<Option<usize>>, ProverError>
Check a proof preimage without generating a proof.
Sourcepub async fn prove_tx(
self: &Arc<Self>,
tx: Transaction<Signature, ProofPreimageMarker, PedersenRandomness, InMemoryDB>,
contract_keys: HashMap<String, ProvingKeyMaterial>,
) -> Result<ProveTxOutput, ProverError>
pub async fn prove_tx( self: &Arc<Self>, tx: Transaction<Signature, ProofPreimageMarker, PedersenRandomness, InMemoryDB>, contract_keys: HashMap<String, ProvingKeyMaterial>, ) -> Result<ProveTxOutput, ProverError>
Prove an entire Transaction in one call.
Sourcepub async fn prove_tx_bytes(
self: &Arc<Self>,
payload: &[u8],
) -> Result<Vec<u8>, ProverError>
pub async fn prove_tx_bytes( self: &Arc<Self>, payload: &[u8], ) -> Result<Vec<u8>, ProverError>
Bytes-in / bytes-out wrapper around Self::prove_tx.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ProverEngine
impl !UnwindSafe for ProverEngine
impl Forget for ProverEngine
impl Freeze for ProverEnginewhere
*const ArcInner<CachingParamsProvider> is !null: Freeze,
PhantomData<ArcInner<CachingParamsProvider>>: Freeze,
*const ArcInner<OnceLock<Arc<BuiltinResolver>>> is !null: Freeze,
PhantomData<ArcInner<OnceLock<Arc<BuiltinResolver>>>>: Freeze,
*const ArcInner<ParsedCircuitCache> is !null: Freeze,
PhantomData<ArcInner<ParsedCircuitCache>>: Freeze,
*const ArcInner<Semaphore> is !null: Freeze,
PhantomData<ArcInner<Semaphore>>: Freeze,
*const ArcInner<Atomic<usize>> is !null: Freeze,
PhantomData<ArcInner<Atomic<usize>>>: Freeze,
impl Move for ProverEngine
impl Send for ProverEngine
impl Sync for ProverEngine
impl Unpin for ProverEngine
impl UnsafeUnpin for ProverEnginewhere
*const ArcInner<CachingParamsProvider> is !null: UnsafeUnpin,
PhantomData<ArcInner<CachingParamsProvider>>: UnsafeUnpin,
*const ArcInner<OnceLock<Arc<BuiltinResolver>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<OnceLock<Arc<BuiltinResolver>>>>: UnsafeUnpin,
*const ArcInner<ParsedCircuitCache> is !null: UnsafeUnpin,
PhantomData<ArcInner<ParsedCircuitCache>>: UnsafeUnpin,
*const ArcInner<Semaphore> is !null: UnsafeUnpin,
PhantomData<ArcInner<Semaphore>>: UnsafeUnpin,
*const ArcInner<Atomic<usize>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<usize>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Envelope<PhantomData<T>> for T
impl<T> Envelope<PhantomData<T>> for T
Source§fn into_envelope(&self) -> PhantomData<T>
fn into_envelope(&self) -> PhantomData<T>
Source§fn envelope_data(&self) -> Vec<u8> ⓘwhere
T: Serializable + Tagged,
fn envelope_data(&self) -> Vec<u8> ⓘwhere
T: Serializable + Tagged,
Source§fn envelope_write(&self, writer: impl Write) -> Result<(), Error>where
T: Serializable + Tagged,
fn envelope_write(&self, writer: impl Write) -> Result<(), Error>where
T: Serializable + Tagged,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SyncDeps for T
impl<T> SyncDeps for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.