1
+ use std:: borrow:: Cow ;
1
2
use std:: cmp:: max;
2
3
use std:: collections:: BTreeMap ;
3
4
use std:: path:: { Path , PathBuf } ;
@@ -83,11 +84,11 @@ impl CacheInfo {
83
84
// If no cache keys were defined, use the defaults.
84
85
let cache_keys = cache_keys. unwrap_or_else ( || {
85
86
vec ! [
86
- CacheKey :: Path ( "pyproject.toml" . to_string ( ) ) ,
87
- CacheKey :: Path ( "setup.py" . to_string ( ) ) ,
88
- CacheKey :: Path ( "setup.cfg" . to_string ( ) ) ,
87
+ CacheKey :: Path ( Cow :: Borrowed ( "pyproject.toml" ) ) ,
88
+ CacheKey :: Path ( Cow :: Borrowed ( "setup.py" ) ) ,
89
+ CacheKey :: Path ( Cow :: Borrowed ( "setup.cfg" ) ) ,
89
90
CacheKey :: Directory {
90
- dir: "src" . to_string ( ) ,
91
+ dir: Cow :: Borrowed ( "src" ) ,
91
92
} ,
92
93
]
93
94
} ) ;
@@ -97,14 +98,14 @@ impl CacheInfo {
97
98
for cache_key in cache_keys {
98
99
match cache_key {
99
100
CacheKey :: Path ( file) | CacheKey :: File { file } => {
100
- if file. chars ( ) . any ( |c| matches ! ( c, '*' | '?' | '[' | '{' ) ) {
101
+ if file. as_ref ( ) . chars ( ) . any ( |c| matches ! ( c, '*' | '?' | '[' | '{' ) ) {
101
102
// Defer globs to a separate pass.
102
103
globs. push ( file) ;
103
104
continue ;
104
105
}
105
106
106
107
// Treat the path as a file.
107
- let path = directory. join ( & file) ;
108
+ let path = directory. join ( file. as_ref ( ) ) ;
108
109
let metadata = match path. metadata ( ) {
109
110
Ok ( metadata) => metadata,
110
111
Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
@@ -126,7 +127,7 @@ impl CacheInfo {
126
127
}
127
128
CacheKey :: Directory { dir } => {
128
129
// Treat the path as a directory.
129
- let path = directory. join ( & dir) ;
130
+ let path = directory. join ( dir. as_ref ( ) ) ;
130
131
let metadata = match path. metadata ( ) {
131
132
Ok ( metadata) => metadata,
132
133
Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
@@ -287,11 +288,11 @@ struct ToolUv {
287
288
#[ serde( untagged, rename_all = "kebab-case" , deny_unknown_fields) ]
288
289
pub enum CacheKey {
289
290
/// Ex) `"Cargo.lock"` or `"**/*.toml"`
290
- Path ( String ) ,
291
+ Path ( Cow < ' static , str > ) ,
291
292
/// Ex) `{ file = "Cargo.lock" }` or `{ file = "**/*.toml" }`
292
- File { file : String } ,
293
+ File { file : Cow < ' static , str > } ,
293
294
/// Ex) `{ dir = "src" }`
294
- Directory { dir : String } ,
295
+ Directory { dir : Cow < ' static , str > } ,
295
296
/// Ex) `{ git = true }` or `{ git = { commit = true, tags = false } }`
296
297
Git { git : GitPattern } ,
297
298
/// Ex) `{ env = "UV_CACHE_INFO" }`
0 commit comments