pub struct Counter<M = Unselected> { /* private fields */ }Expand description
Type-safe builder for p4 counter.
Access, set, increment, or delete a persistent variable.
Counters provide long-term variable storage for scripts. Querying a counter that does not exist returns zero; counter names are not stored in the database until set to a nonzero value. Deleting a counter has the same effect as setting it to zero. The compare-and-set form can be used as a building block for higher-level tools and processes.
§Syntax
p4 [g-opts] counter countername
p4 [g-opts] counter [-f -v] countername value
p4 [g-opts] counter [-f] -d countername
p4 [g-opts] counter [-f -v] -i countername
p4 [g-opts] counter [-f] -m [pair list]
p4 [g-opts] counter --from oldvalue --to newvalue counternameThe M type parameter tracks the command form at compile time, starting
as Unselected from Counter::new, which is the bare query form
p4 counter countername: spawn it with the counter name to read the
value. Enter another form with one of Self::set, Self::force,
Self::show_previous, Self::delete, Self::increment, Self::multi, or Self::cas:
SetMode(entered viaSelf::set,Self::force, orSelf::show_previous): set or create the counter; can transition toDeleteMode,IncrementMode, orMultiModepreserving-f, andCounter::show_previoussupplies-vby transitioning to theShowPreviousstate.DeleteMode(-d, entered viaSelf::delete): delete the counter.IncrementMode(-i, entered viaSelf::increment): increment the counter by one and return the new value.MultiMode(-m, entered viaSelf::multi): perform a list of operations in a single invocation.CASMode(--from oldvalue --to newvalue, entered viaSelf::cas): set the counter only if its current value matches.
-v cannot be combined with -d or -m: DeleteMode and MultiMode are only reachable from SetMode while it is in the Unselected state.
Implementations§
Source§impl Counter<Unselected>
impl Counter<Unselected>
Sourcepub fn new(bin: impl Into<PathBuf>, global_opts: GlobalOpts) -> Self
pub fn new(bin: impl Into<PathBuf>, global_opts: GlobalOpts) -> Self
Creates a new p4 counter command in the bare query form
p4 counter countername.
bin is the path to the Perforce command-line executable. In this
state, spawn with the counter name via ParameterizedSpawn::spawn_with
to read its value; use one of the builder methods to select another
form.
Sourcepub fn set(self) -> Counter<SetMode<Unselected>>
pub fn set(self) -> Counter<SetMode<Unselected>>
Enters the set form: p4 counter [-f -v] countername value.
Spawn the returned builder with the counter name and the value to
assign.
Use Counter::force to supply -f, or Counter::show_previous to supply -v.
Sourcepub fn force(self, v: bool) -> Counter<SetMode<Unselected>>
pub fn force(self, v: bool) -> Counter<SetMode<Unselected>>
Enters the set form with -f preset.
v sets the initial state of the -f flag, which permits setting or
deleting counters reserved for use by P4 Server. Spawn the returned
builder with the counter name and the value to assign, or transition
to the delete or increment form.
Sourcepub fn show_previous(self) -> Counter<SetMode<ShowPrevious>>
pub fn show_previous(self) -> Counter<SetMode<ShowPrevious>>
Enters the set form with -v supplied, displaying the previous value
after the set.
Spawn the returned builder with the counter name and the value to assign, or transition to the increment form.
Sourcepub fn delete(self) -> Counter<DeleteMode>
pub fn delete(self) -> Counter<DeleteMode>
Enters the delete form: p4 counter [-f] -d countername.
Spawn the returned builder with the counter name to delete.
Sourcepub fn increment(self) -> Counter<IncrementMode<Unselected>>
pub fn increment(self) -> Counter<IncrementMode<Unselected>>
Enters the increment form: p4 counter [-f -v] -i countername.
Spawn the returned builder with the counter name to increment.
Sourcepub fn multi(self) -> Counter<MultiMode>
pub fn multi(self) -> Counter<MultiMode>
Enters the multi form: p4 counter [-f] -m [pair list].
Spawn the returned builder with the list of name/value pairs and
--prefixed names to delete. Use Counter::force on the returned
builder to supply -f; transitioning from the set form preserves an
already selected -f.
Sourcepub fn cas(
self,
old_value: impl Into<String>,
new_value: impl Into<String>,
) -> Counter<CASMode>
pub fn cas( self, old_value: impl Into<String>, new_value: impl Into<String>, ) -> Counter<CASMode>
Enters the compare-and-set form: p4 counter --from oldvalue --to newvalue countername.
old_value is the value the counter must currently hold; new_value
is the value to assign when it matches. Spawn the returned builder
with the counter name.
Source§impl<M> Counter<M>
impl<M> Counter<M>
Sourcepub fn get_global_opts(&self) -> &GlobalOpts
pub fn get_global_opts(&self) -> &GlobalOpts
Sourcepub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self
pub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self
Sourcepub fn global_opts(self, v: GlobalOpts) -> Self
pub fn global_opts(self, v: GlobalOpts) -> Self
Source§impl Counter<SetMode<Unselected>>
impl Counter<SetMode<Unselected>>
Sourcepub fn get_force(&self) -> bool
pub fn get_force(&self) -> bool
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Sourcepub fn set_force(&mut self, v: bool) -> &mut Self
pub fn set_force(&mut self, v: bool) -> &mut Self
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Sourcepub fn force(self, v: bool) -> Self
pub fn force(self, v: bool) -> Self
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Sourcepub fn show_previous(self) -> Counter<SetMode<ShowPrevious>>
pub fn show_previous(self) -> Counter<SetMode<ShowPrevious>>
§Description
-v
Display the previous value of the specified counter after the counter has been set.
Transitions this command to the ShowPrevious state, which also
permits transitioning to the increment form (-v is valid with -i
but not with -d).
Sourcepub fn delete(self) -> Counter<DeleteMode>
pub fn delete(self) -> Counter<DeleteMode>
Transitions to the delete form (-d), preserving the -f flag.
This transition is unavailable from the ShowPrevious state because -v cannot be combined with -d.
Sourcepub fn increment(self) -> Counter<IncrementMode<Unselected>>
pub fn increment(self) -> Counter<IncrementMode<Unselected>>
Transitions to the increment form (-i), preserving the -f flag.
Sourcepub fn multi(self) -> Counter<MultiMode>
pub fn multi(self) -> Counter<MultiMode>
Transitions to the multi form (-m), preserving the -f flag.
This transition is unavailable from the ShowPrevious state because -v cannot be combined with -m.
Source§impl Counter<SetMode<ShowPrevious>>
impl Counter<SetMode<ShowPrevious>>
Sourcepub fn get_force(&self) -> bool
pub fn get_force(&self) -> bool
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Sourcepub fn set_force(&mut self, v: bool) -> &mut Self
pub fn set_force(&mut self, v: bool) -> &mut Self
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Sourcepub fn force(self, v: bool) -> Self
pub fn force(self, v: bool) -> Self
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Sourcepub fn increment(self) -> Counter<IncrementMode<ShowPrevious>>
pub fn increment(self) -> Counter<IncrementMode<ShowPrevious>>
Transitions to the increment form (-i), preserving the -f and -v
flags.
Source§impl Counter<DeleteMode>
impl Counter<DeleteMode>
Sourcepub fn get_force(&self) -> bool
pub fn get_force(&self) -> bool
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Source§impl<B> Counter<IncrementMode<B>>
impl<B> Counter<IncrementMode<B>>
Sourcepub fn get_force(&self) -> bool
pub fn get_force(&self) -> bool
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Source§impl Counter<IncrementMode<Unselected>>
impl Counter<IncrementMode<Unselected>>
Sourcepub fn show_previous(self) -> Counter<IncrementMode<ShowPrevious>>
pub fn show_previous(self) -> Counter<IncrementMode<ShowPrevious>>
§Description
-v
Display the previous value of the specified counter after the counter has been incremented.
Transitions this command to the ShowPrevious state.
Source§impl Counter<MultiMode>
impl Counter<MultiMode>
Sourcepub fn get_force(&self) -> bool
pub fn get_force(&self) -> bool
§Description
-f
Set or delete counters that are reserved for use by P4 Server (listed
in p4 help counters). Never set the change counter to a value that
is lower than its current value.
Source§impl Counter<CASMode>
impl Counter<CASMode>
Sourcepub fn get_old_value(&self) -> &str
pub fn get_old_value(&self) -> &str
§Description
–from oldvalue
The value the counter must currently hold for the new value to be assigned.
Sourcepub fn set_old_value(&mut self, v: impl Into<String>) -> &mut Self
pub fn set_old_value(&mut self, v: impl Into<String>) -> &mut Self
§Description
–from oldvalue
The value the counter must currently hold for the new value to be assigned.
Sourcepub fn old_value(self, v: impl Into<String>) -> Self
pub fn old_value(self, v: impl Into<String>) -> Self
§Description
–from oldvalue
The value the counter must currently hold for the new value to be assigned.
Sourcepub fn get_new_value(&self) -> &str
pub fn get_new_value(&self) -> &str
§Description
–to newvalue
The value to assign to the counter when its current value matches
oldvalue.
Sourcepub fn set_new_value(&mut self, v: impl Into<String>) -> &mut Self
pub fn set_new_value(&mut self, v: impl Into<String>) -> &mut Self
§Description
–to newvalue
The value to assign to the counter when its current value matches
oldvalue.
Trait Implementations§
Source§impl<S, A, B> ParameterizedSpawn<(A, B)> for Counter<SetMode<S>>
impl<S, A, B> ParameterizedSpawn<(A, B)> for Counter<SetMode<S>>
Source§fn spawn_with(
&mut self,
(countername, value): (A, B),
) -> Result<Self::Output, Self::Error>
fn spawn_with( &mut self, (countername, value): (A, B), ) -> Result<Self::Output, Self::Error>
Spawns p4 counter [-f -v] countername value with the given counter
name and value as a child process with piped standard output and error
streams; use the returned Child handle to wait for it or interact
with it.
type Output = Child
type Error = Error
Source§impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<Unselected>
impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<Unselected>
Source§fn spawn_with(
&mut self,
(countername): (I,),
) -> Result<Self::Output, Self::Error>
fn spawn_with( &mut self, (countername): (I,), ) -> Result<Self::Output, Self::Error>
Spawns p4 counter countername with the given counter name as a child
process with piped standard output and error streams; use the returned
Child handle to wait for it or interact with it.
type Output = Child
type Error = Error
Source§impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<DeleteMode>
impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<DeleteMode>
Source§fn spawn_with(
&mut self,
(countername): (I,),
) -> Result<Self::Output, Self::Error>
fn spawn_with( &mut self, (countername): (I,), ) -> Result<Self::Output, Self::Error>
Spawns p4 counter [-f] -d countername with the given counter name as
a child process with piped standard output and error streams; use the
returned Child handle to wait for it or interact with it.
type Output = Child
type Error = Error
Source§impl<S, I> ParameterizedSpawn<(I,)> for Counter<IncrementMode<S>>
impl<S, I> ParameterizedSpawn<(I,)> for Counter<IncrementMode<S>>
Source§fn spawn_with(
&mut self,
(countername): (I,),
) -> Result<Self::Output, Self::Error>
fn spawn_with( &mut self, (countername): (I,), ) -> Result<Self::Output, Self::Error>
Spawns p4 counter [-f -v] -i countername with the given counter name
as a child process with piped standard output and error streams; use
the returned Child handle to wait for it or interact with it.
type Output = Child
type Error = Error
Source§impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<CASMode>
Available on non-crate feature lt2016_1 only.
impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<CASMode>
lt2016_1 only.Source§fn spawn_with(
&mut self,
(countername): (I,),
) -> Result<Self::Output, Self::Error>
fn spawn_with( &mut self, (countername): (I,), ) -> Result<Self::Output, Self::Error>
Spawns p4 counter --from oldvalue --to newvalue countername with the
given counter name as a child process with piped standard output and
error streams; use the returned Child handle to wait for it or
interact with it.
type Output = Child
type Error = Error
Source§impl<S, I> ParameterizedSpawn<(S,)> for Counter<MultiMode>
impl<S, I> ParameterizedSpawn<(S,)> for Counter<MultiMode>
Source§fn spawn_with(&mut self, (pairs): (S,)) -> Result<Self::Output, Self::Error>
fn spawn_with(&mut self, (pairs): (S,)) -> Result<Self::Output, Self::Error>
Spawns p4 counter [-f] -m with the given pair list as a child
process with piped standard output and error streams; use the returned
Child handle to wait for it or interact with it.