## LocalFingerprint

# Enum LocalFingerprint

Source

    enum LocalFingerprint {
        Precalculated(String),
        CheckDepInfo {
            dep_info: PathBuf,
            checksum: bool,
        },
        RerunIfChanged {
            output: PathBuf,
            paths: Vec<PathBuf>,
        },
        RerunIfEnvChanged {
            var: String,
            val: Option<String>,
        },
    }

Expand description

A `LocalFingerprint` represents something that we use to detect direct changes to a `Fingerprint`.

This is where we track file information, env vars, etc. This `LocalFingerprint` struct is hashed and if the hash changes will force a recompile of any fingerprint it’s included into. Note that the “local” terminology comes from the fact that it only has to do with one crate, and `Fingerprint` tracks the transitive propagation of fingerprint changes.

Note that because this is hashed its contents are carefully managed. Like mentioned in the above module docs, we don’t want to hash absolute paths or mtime information.

Also note that a `LocalFingerprint` is used in `check_filesystem` to detect when the filesystem contains stale information (based on mtime currently). The paths here don’t change much between compilations but they’re used as inputs when we probe the filesystem looking at information.

## Variants§

§

### Precalculated(String)

This is a precalculated fingerprint which has an opaque string we just hash as usual. This variant is primarily used for rustdoc where we don’t have a dep-info file to compare against.

This is also used for build scripts with no `rerun-if-*` statements, but that’s overall a mistake and causes bugs in Cargo. We shouldn’t use this for build scripts.

§

### CheckDepInfo

This is used for crate compilations. The `dep_info` file is a relative path anchored at `target_root(...)` to the dep-info file that Cargo generates (which is a custom serialization after parsing rustc’s own `dep-info` output).

The `dep_info` file, when present, also lists a number of other files for us to look at. If any of those files are newer than this file then we need to recompile.

If the `checksum` bool is true then the `dep_info` file is expected to contain file checksums instead of file mtimes.

#### Fields

§`dep_info: PathBuf`
§`checksum: bool`
§

### RerunIfChanged

This represents a nonempty set of `rerun-if-changed` annotations printed out by a build script. The `output` file is a relative file anchored at `target_root(...)` which is the actual output of the build script. That output has already been parsed and the paths printed out via `rerun-if-changed` are listed in `paths`. The `paths` field is relative to `pkg.root()`

This is considered up-to-date if all of the `paths` are older than `output`, otherwise we need to recompile.

#### Fields

§`output: PathBuf`
§`paths: Vec<PathBuf>`
§

### RerunIfEnvChanged

This represents a single `rerun-if-env-changed` annotation printed by a build script. The exact env var and value are hashed here. There’s no filesystem dependence here, and if the values are changed the hash will change forcing a recompile.

#### Fields

§`var: String`
§`val: Option<String>`

## Implementations§

Source§

### impl LocalFingerprint

Source

#### fn from_env<K: AsRef<str>>( key: K, env_config: &Arc<HashMap<String, OsString>>, ) -> LocalFingerprint

Read the environment variable of the given env `key`, and creates a new `LocalFingerprint::RerunIfEnvChanged` for it. The `env_config` is used firstly to check if the env var is set in the config system as some envs need to be overridden. If not, it will fallback to `std::env::var`.

Source

#### fn find_stale_item( &self, mtime_cache: &mut HashMap<PathBuf, FileTime>, checksum_cache: &mut HashMap<PathBuf, Checksum>, pkg: &Package, build_root: &Path, cargo_exe: &Path, gctx: &GlobalContext, ) -> CargoResult<Option<StaleItem>>

Checks dynamically at runtime if this `LocalFingerprint` has a stale item inside of it.

The main purpose of this function is to handle two different ways fingerprints can be invalidated:

- One is a dependency listed in rustc’s dep-info files is invalid. Note that these could either be env vars or files. We check both here.

- Another is the `rerun-if-changed` directive from build scripts. This is where we’ll find whether files have actually changed

Source

#### fn kind(&self) -> &'static str

## Trait Implementations§

Source§

### impl Debug for LocalFingerprint

Source§

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

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

### impl<'de> Deserialize<'de> for LocalFingerprint

Source§

#### fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

### impl Hash for LocalFingerprint

Source§

#### fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given `Hasher`. Read more
1.3.0 · Source§

#### fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given `Hasher`. Read more
Source§

### impl Serialize for LocalFingerprint

Source§

#### fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

## Auto Trait Implementations§

§

### impl Freeze for LocalFingerprint

§

### impl RefUnwindSafe for LocalFingerprint

§

### impl Send for LocalFingerprint

§

### impl Sync for LocalFingerprint

§

### impl Unpin for LocalFingerprint

§

### impl UnwindSafe for LocalFingerprint

## 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> From<T> for T

Source§

#### fn from(t: T) -> T

Returns the argument unchanged.

§

### impl<T> Instrument for T

§

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [`Span`], returning an `Instrumented` wrapper. Read more
§

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more
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> IntoEither for T

Source§

#### fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts `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 more
Source§

#### fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts `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 more
§

### impl<T> Pointable for T

§

#### const ALIGN: usize

The alignment of pointer.
§

#### type Init = T

The type for initializers.
§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

### impl<T> Same for T

Source§

#### type Output = T

Should always be `Self`
Source§

### impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

#### fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

#### fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

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

Source§

#### type Error = Infallible

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

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

### impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

#### fn vzip(self) -> V

§

### impl<T> WithSubscriber for T

§

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a [`WithDispatch`] wrapper. Read more
§

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a [`WithDispatch`] wrapper. Read more
Source§

### impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

## Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain `repr(...)` attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 56 bytes

Size for each variant:

- `Precalculated`: 31 bytes
- `CheckDepInfo`: 31 bytes
- `RerunIfChanged`: 55 bytes
- `RerunIfEnvChanged`: 55 bytes