pub struct GitSource { /* private fields */ }Expand description
A file in a git repository, as a configuration source.
Built with GitSource::builder. Not Clone: the working directory is
claimed by one source, and two clones fetching into it would interleave
their ref updates. Wrap it in an Arc if two places need one.
Implementations§
Source§impl GitSource
impl GitSource
Sourcepub fn builder(url: impl Into<String>) -> Builder
pub fn builder(url: impl Into<String>) -> Builder
A source reading from the repository at url.
url is anything git understands: https://…, ssh://…,
git@host:org/repo.git, or a local path.
Sourcepub fn watch<F>(
&self,
watching: &Watching,
interval: Duration,
on_change: F,
) -> Result<(), Error>
pub fn watch<F>( &self, watching: &Watching, interval: Duration, on_change: F, ) -> Result<(), Error>
Calls on_change when the ref moves, checking every interval.
Polling, because git offers nothing better — and advertisement polling, because transferring a commit every tick to discover it has not changed would be a poor thing to do to a git host. Each tick is one handshake and one ref advertisement; only a ref that moved costs a transfer.
The current value is not delivered at startup, for the same reason a file watcher does not report an edit when it starts. Fetch first if the starting value matters, which it usually does:
sink.apply(source.fetch()?)?;
source.watch(&watching, Duration::from_secs(60), move |document| sink.apply(document))A host that is away, a ref that has been deleted, a document that does
not parse — none of those end the watch. It waits out the interval and
tries again. stop is noticed within a quarter second regardless of how
long interval is.
§A source reading several files can be watched
It is the only one in this family that can. Every other store refuses a watch on a set, and the reason is written down: waking on a change to one key and then re-reading key by key collects the new value of that key and whatever the others happen to be halfway through a deployment — a document that never existed at any instant, installed and then served until the next change.
Neither half of that applies here. What moves is a ref, and what a ref names is a commit — so the watch does not wake on one file, it wakes on the repository, and the re-read that follows takes every file out of that one commit’s tree. A deployment that writes four files in one commit is delivered as one document; a deployment that writes them in four commits is delivered as up to four documents, each of which is a state the repository really was in. There is no interleaving to be had.
The cost is the other direction, and it is the same cost a single-file
watch has always had: a commit that touches nothing this source reads
still moves the ref, so on_change is called with a document identical
to the last one. A spurious delivery, never a torn one — dynamic-config
diffs it and reports no changes.
§Errors
If the host refuses a credential that cannot be replaced — a token
handed in as a constant is the same token next tick, so retrying it
forever would be a hot loop against a host that may well start locking
the account. A credential that came from a closure is refreshed and
retried instead, and only ends the watch if the fresh one is refused
too. Or if on_change returns an error, which ends the watch — so a
caller that wants to survive a bad document should log it and return
Ok.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for GitSource
impl !RefUnwindSafe for GitSource
impl !UnwindSafe for GitSource
impl Send for GitSource
impl Sync for GitSource
impl Unpin for GitSource
impl UnsafeUnpin for GitSource
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<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> ⓘ
impl<T> MaybeSendSync for T
Source§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);