Skip to main content

Counter

Struct Counter 

Source
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 countername

The 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:

-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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

pub fn get_bin(&self) -> &Path

Get the Perforce command path.

Source

pub fn set_bin(&mut self, bin: impl Into<PathBuf>) -> &mut Self

Set the Perforce command path.

Source

pub fn bin(self, bin: impl Into<PathBuf>) -> Self

Set the Perforce command path.

Source

pub fn get_global_opts(&self) -> &GlobalOpts

§Description

g-opts

See Global options.

Source

pub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self

§Description

g-opts

See Global options.

Source

pub fn global_opts(self, v: GlobalOpts) -> Self

§Description

g-opts

See Global options.

Source§

impl Counter<SetMode<Unselected>>

Source

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

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.

Source

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.

Source

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).

Source

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.

Source

pub fn increment(self) -> Counter<IncrementMode<Unselected>>

Transitions to the increment form (-i), preserving the -f flag.

Source

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>>

Source

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

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.

Source

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.

Source

pub fn increment(self) -> Counter<IncrementMode<ShowPrevious>>

Transitions to the increment form (-i), preserving the -f and -v flags.

Source§

impl Counter<DeleteMode>

Source

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

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.

Source

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.

Source§

impl<B> Counter<IncrementMode<B>>

Source

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

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.

Source

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.

Source§

impl Counter<IncrementMode<Unselected>>

Source

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>

Source

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

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.

Source

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.

Source§

impl Counter<CASMode>

Source

pub fn get_old_value(&self) -> &str

§Description

–from oldvalue

The value the counter must currently hold for the new value to be assigned.

Source

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.

Source

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.

Source

pub fn get_new_value(&self) -> &str

§Description

–to newvalue

The value to assign to the counter when its current value matches oldvalue.

Source

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.

Source

pub fn new_value(self, v: impl Into<String>) -> Self

§Description

–to newvalue

The value to assign to the counter when its current value matches oldvalue.

Trait Implementations§

Source§

impl<M: Clone> Clone for Counter<M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Debug> Debug for Counter<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: Default> Default for Counter<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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>

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.

Source§

type Output = Child

Source§

type Error = Error

Source§

impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<Unselected>

Source§

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.

Source§

type Output = Child

Source§

type Error = Error

Source§

impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<DeleteMode>

Source§

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.

Source§

type Output = Child

Source§

type Error = Error

Source§

impl<S, I> ParameterizedSpawn<(I,)> for Counter<IncrementMode<S>>

Source§

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.

Source§

type Output = Child

Source§

type Error = Error

Source§

impl<I: AsRef<OsStr>> ParameterizedSpawn<(I,)> for Counter<CASMode>

Available on non-crate feature lt2016_1 only.
Source§

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.

Source§

type Output = Child

Source§

type Error = Error

Source§

impl<S, I> ParameterizedSpawn<(S,)> for Counter<MultiMode>
where S: IntoIterator<Item = I>, I: AsRef<OsStr>,

Source§

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.

Source§

type Output = Child

Source§

type Error = Error

Source§

impl<M: ExclusiveOption> SubCommand for Counter<M>

Source§

fn name(&self) -> &str

Source§

fn inject_local_args(&self, command: &mut Command)

Source§

fn global_opts(&self) -> Option<&GlobalOpts>

Source§

fn inject_args(&self, command: &mut Command)

Source§

fn setup_command<S: AsRef<OsStr>>(&self, bin: S) -> Command

Auto Trait Implementations§

§

impl<M> Freeze for Counter<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Counter<M>
where M: RefUnwindSafe,

§

impl<M> Send for Counter<M>
where M: Send,

§

impl<M> Sync for Counter<M>
where M: Sync,

§

impl<M> Unpin for Counter<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for Counter<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for Counter<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, T1> OutputExt1<T1> for T
where T: SpawnExt1<T1, Output = Child, Error = Error>,

Source§

fn output( &mut self, a: T1, ) -> Result<Output, <T as ParameterizedSpawn<(T1,)>>::Error>

Source§

impl<T, T1, T2> OutputExt2<T1, T2> for T
where T: SpawnExt2<T1, T2, Output = Child, Error = Error>,

Source§

fn output( &mut self, a: T1, b: T2, ) -> Result<Output, <T as ParameterizedSpawn<(T1, T2)>>::Error>

Source§

impl<T, I> ParameterizedOutput<I> for T
where T: ParameterizedSpawn<I, Output = Child, Error = Error>,

Source§

type Error = Error

Source§

fn output_with( &mut self, input: I, ) -> Result<Output, <T as ParameterizedOutput<I>>::Error>

Source§

impl<T, T1> SpawnExt1<T1> for T

Source§

fn spawn( &mut self, a: T1, ) -> Result<<T as ParameterizedSpawn<(T1,)>>::Output, <T as ParameterizedSpawn<(T1,)>>::Error>

Source§

impl<T, T1, T2> SpawnExt2<T1, T2> for T

Source§

fn spawn( &mut self, a: T1, b: T2, ) -> Result<<T as ParameterizedSpawn<(T1, T2)>>::Output, <T as ParameterizedSpawn<(T1, T2)>>::Error>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.