#[non_exhaustive]pub struct ProxyConfig {
pub effective: ProxyMode,
pub sources: Vec<(ProxyConfigSource, ProxyMode)>,
pub fallbacks: Vec<ProxyConfigSource>,
pub captured_at: SystemTime,
}Expand description
Point-in-time system proxy snapshot.
Backend-built: sources descending precedence, effective = first (or Direct).
ProxyConfig::from_ordered_sources enforces that invariant; ProxyConfig::new
remains available for caller-defined resolved configurations. PartialEq ignores
captured_at.
let a = ProxyConfig::from_source(ProxyConfigSource::Registry, ProxyMode::Direct);
let mut b = a.clone();
b.captured_at = SystemTime::UNIX_EPOCH;
assert_eq!(a, b);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.effective: ProxyModeResolved mode after platform precedence.
sources: Vec<(ProxyConfigSource, ProxyMode)>Descending precedence; backend snapshots: first wins (or Direct if empty).
fallbacks: Vec<ProxyConfigSource>Sources that were consulted, could not be read, and were left out of sources
rather than failing the whole read.
A source absent from both lists was not configured; a source listed here is one
the machine may well be configured with, whose value this read did not learn. That
is the difference sources alone cannot express, and until this
field existed the only record of it was a log line — so a consumer built without
the tracing feature had none at all.
Backend snapshots only: nothing here is derived from the modes, so
ProxyConfig::new and the constructors below leave it empty and
ProxyConfig::with_fallbacks is what fills it in.
Unlike captured_at this is compared by PartialEq, which is what makes a
watcher deliver the snapshot where a degradation appears or clears. Excluding it
would be worse than merely quiet: the watcher’s equality skip keeps the snapshot it
already holds, so a degradation that healed would be reported for the rest of the
watcher’s life.
captured_at: SystemTimeCapture time; excluded from equality.
Implementations§
Source§impl ProxyConfig
impl ProxyConfig
Sourcepub fn new(
effective: ProxyMode,
sources: Vec<(ProxyConfigSource, ProxyMode)>,
) -> Self
pub fn new( effective: ProxyMode, sources: Vec<(ProxyConfigSource, ProxyMode)>, ) -> Self
Build a snapshot stamped with now.
Sourcepub fn with_fallbacks(self, fallbacks: Vec<ProxyConfigSource>) -> Self
pub fn with_fallbacks(self, fallbacks: Vec<ProxyConfigSource>) -> Self
Record the sources this read could not learn the value of.
See fallbacks. Takes the whole list rather than appending, so
a backend that assembles one alongside its sources hands it over in one place.
Sourcepub fn from_ordered_sources(
sources: Vec<(ProxyConfigSource, ProxyMode)>,
) -> Self
pub fn from_ordered_sources( sources: Vec<(ProxyConfigSource, ProxyMode)>, ) -> Self
Build a snapshot from sources already ordered by descending precedence.
The first mode becomes effective; an empty list becomes
ProxyMode::Direct. The source order and every losing source are preserved.
Sourcepub fn from_source(source: ProxyConfigSource, mode: ProxyMode) -> Self
pub fn from_source(source: ProxyConfigSource, mode: ProxyMode) -> Self
Snapshot whose effective value comes from exactly one source.
Sourcepub fn source(&self, source: ProxyConfigSource) -> Option<&ProxyMode>
pub fn source(&self, source: ProxyConfigSource) -> Option<&ProxyMode>
Mode for a specific source, if consulted.
Sourcepub fn with_env(self, env: &ProxyEnv, precedence: EnvPrecedence) -> Self
pub fn with_env(self, env: &ProxyEnv, precedence: EnvPrecedence) -> Self
Fold the process environment into this snapshot as one more source.
The environment enters whole: one entry in sources, ranked
against the OS sources rather than merged into them slot by slot. Setting only
http_proxy therefore does not leave the OS’s https proxy in place — the winning
source answers for every scheme, and an environment with no https entry resolves
https to direct. all_proxy is how the environment covers the schemes it did not
name.
What the fold does depends on the environment’s shape.
ProxyEnv::is_configured separates the first shape from the other two; what
separates those is whether anything was dropped, which ProxyEnv::rejected and
ProxyEnv::bypass’s own rejections answer.
- Configured — it takes the rank
precedenceasks for. Ano_proxywith no proxy variable beside it is this shape, andProxyEnv::to_modeturns it intoDirect: underBeforeSystemit does not add a bypass to the OS proxy, it outranks that proxy and every host resolves direct. The error is toward bypassing more than the caller listed, never toward proxying a host they asked to exclude. - Present but specifying nothing — appended to
sourcesand never madeeffective, so a typo cannot mask the OS. Where every*_proxyvalue was malformed,ProxyEnv::to_modeanswersManualand the drops come back out ofsource. Where instead ano_proxylost every entry it held,to_modeanswersDirect, which has nowhere to hold an exclusion list: the entry records only that the environment was there and lost something, and the text of the drop stays onProxyEnv::bypass().rejected. - Specifying nothing and dropping nothing —
selfis returned untouched. Usually that means the variables are unset, but ano_proxythat parses to no rules and no rejections (no_proxy=,no_proxy=",") lands here too: it was set, and the snapshot keeps no evidence that it was.
Being configured and having dropped something are not exclusive. no_proxy=.corp
beside an http_proxy that does not parse is configured — the bypass list is the
configuration — so it takes the rank, and the dropped scheme rides in with it: http
then answers Error::ProxyEntryUnusable instead
of falling through to the OS proxy or to direct. Silently sending the scheme whose
value was typed wrong straight out is the failure this crate exists to make visible.
Fold an environment in once. A second with_env can leave a second
Env entry in sources, and source
answers with whichever is first — which the second environment’s shape decides as much
as the precedence does.
captured_at becomes the older of the two reads, except in the
third shape, where nothing is folded in: the result is only as fresh as its stalest
half. effective is otherwise left alone, including where that leaves it disagreeing
with sources[0].
let env = ProxyEnv::from_vars([("http_proxy", "http://env.corp:3128")]).unwrap();
let os = ProxyConfig::from_source(ProxyConfigSource::Registry, ProxyMode::Direct);
let merged = os.with_env(&env, EnvPrecedence::BeforeSystem);
assert!(matches!(merged.effective, ProxyMode::Manual { .. }));
assert_eq!(merged.sources.len(), 2);
assert!(merged.source(ProxyConfigSource::Registry).is_some());Trait Implementations§
Source§impl Clone for ProxyConfig
impl Clone for ProxyConfig
Source§fn clone(&self) -> ProxyConfig
fn clone(&self) -> ProxyConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProxyConfig
impl Debug for ProxyConfig
Source§impl Default for ProxyConfig
impl Default for ProxyConfig
impl Eq for ProxyConfig
Auto Trait Implementations§
impl Freeze for ProxyConfig
impl RefUnwindSafe for ProxyConfig
impl Send for ProxyConfig
impl Sync for ProxyConfig
impl Unpin for ProxyConfig
impl UnsafeUnpin for ProxyConfig
impl UnwindSafe for ProxyConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
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> 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.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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.