Skip to main content

CompletionCache

Struct CompletionCache 

Source
pub struct CompletionCache { /* private fields */ }
Expand description

A thread-safe cache for completion results

The cache automatically expires entries after a configurable duration to ensure that completions remain fresh while still providing performance benefits.

Implementations§

Source§

impl CompletionCache

Source

pub fn new(ttl: Duration) -> Self

Creates a new completion cache with the specified time-to-live

§Arguments
  • ttl - How long cached entries should remain valid
Examples found in repository?
examples/cached_completion_demo.rs (line 40)
38fn main() {
39    // Create a shared cache with 10-second TTL
40    let cache = Arc::new(CompletionCache::new(Duration::from_secs(10)));
41
42    let app = CommandBuilder::new("kubectl")
43        .short("Kubernetes command-line tool with cached completions")
44        .flag(
45            Flag::new("namespace")
46                .short('n')
47                .usage("The namespace scope for this CLI request")
48                .value_type(FlagType::String)
49                .default(flag_rs::FlagValue::String("default".to_string())),
50        )
51        .subcommand({
52            let cache_clone = Arc::clone(&cache);
53            CommandBuilder::new("get")
54                .short("Display one or many resources")
55                .subcommand({
56                    let cache_for_pods = Arc::clone(&cache_clone);
57                    CommandBuilder::new("pods")
58                        .short("List pods with cached completion")
59                        .arg_completion(move |ctx, prefix| {
60                            let start = Instant::now();
61
62                            // Generate cache key
63                            let cache_key = CompletionCache::make_key(
64                                &["kubectl".to_string(), "get".to_string(), "pods".to_string()],
65                                prefix,
66                                ctx.flags(),
67                            );
68
69                            // Try to get from cache first
70                            if let Some(cached_result) = cache_for_pods.get(&cache_key) {
71                                eprintln!("✓ Cache hit! Completed in {:?}", start.elapsed());
72                                return Ok(cached_result);
73                            }
74
75                            eprintln!("✗ Cache miss - fetching completions...");
76
77                            // Perform expensive operation
78                            let items = expensive_completion(prefix);
79                            let mut result = CompletionResult::new();
80
81                            for item in items {
82                                result = result.add_with_description(
83                                    item.clone(),
84                                    format!(
85                                        "Pod in namespace {}",
86                                        ctx.flag("namespace").unwrap_or(&"default".to_string())
87                                    ),
88                                );
89                            }
90
91                            // Add contextual help
92                            if prefix.is_empty() {
93                                result =
94                                    result.add_help_text("Tip: Start typing to filter pod names");
95                            }
96
97                            // Cache the result
98                            cache_for_pods.put(cache_key, result.clone());
99
100                            eprintln!(
101                                "✓ Completed in {:?} (cached for future use)",
102                                start.elapsed()
103                            );
104                            Ok(result)
105                        })
106                        .build()
107                })
108                .subcommand({
109                    let cache_for_services = Arc::clone(&cache_clone);
110                    CommandBuilder::new("services")
111                        .short("List services with cached completion")
112                        .arg_completion(move |ctx, prefix| {
113                            let cache_key = CompletionCache::make_key(
114                                &[
115                                    "kubectl".to_string(),
116                                    "get".to_string(),
117                                    "services".to_string(),
118                                ],
119                                prefix,
120                                ctx.flags(),
121                            );
122
123                            if let Some(cached) = cache_for_services.get(&cache_key) {
124                                eprintln!("✓ Using cached service completions");
125                                return Ok(cached);
126                            }
127
128                            // Simulate expensive operation
129                            let services = expensive_completion(prefix);
130                            let result = CompletionResult::new().extend(services);
131
132                            cache_for_services.put(cache_key, result.clone());
133                            Ok(result)
134                        })
135                        .build()
136                })
137                .build()
138        })
139        .build();
140
141    println!("=== Cached Completion Demo ===\n");
142    println!("This demo shows how completion caching improves performance.\n");
143    println!("To test completions with caching:");
144    println!("1. Set up bash completion:");
145    println!(
146        "   source <({} completion bash)",
147        std::env::args().next().unwrap_or_default()
148    );
149    println!();
150    println!("2. Try tab completion multiple times:");
151    println!(
152        "   {} get pods n<TAB>     # First time: ~500ms (cache miss)",
153        std::env::args().next().unwrap_or_default()
154    );
155    println!(
156        "   {} get pods n<TAB>     # Second time: <1ms (cache hit!)",
157        std::env::args().next().unwrap_or_default()
158    );
159    println!();
160    println!("3. Different prefixes have separate cache entries:");
161    println!(
162        "   {} get pods r<TAB>     # Different prefix = cache miss",
163        std::env::args().next().unwrap_or_default()
164    );
165    println!();
166    println!("4. Flags affect the cache key:");
167    println!(
168        "   {} -n prod get pods n<TAB>  # Different namespace = different cache",
169        std::env::args().next().unwrap_or_default()
170    );
171    println!();
172    println!("Note: Cache entries expire after 10 seconds in this demo.\n");
173    println!("---\n");
174
175    let args: Vec<String> = std::env::args().skip(1).collect();
176
177    // Handle completion requests
178    if std::env::var("KUBECTL_COMPLETE").is_ok() {
179        // When testing completions, show cache status
180        eprintln!("Cache size: {} entries", cache.size());
181    }
182
183    if let Err(e) = app.execute(args) {
184        eprintln!("{}", e);
185        std::process::exit(1);
186    }
187}
Source

pub fn with_default_ttl() -> Self

Creates a new completion cache with a default TTL of 5 seconds

Source

pub fn make_key( command_path: &[String], prefix: &str, flags: &HashMap<String, String>, ) -> String

Generates a cache key from completion context

The key includes the command path and current prefix to ensure we only return cached results for identical contexts.

Examples found in repository?
examples/cached_completion_demo.rs (lines 63-67)
38fn main() {
39    // Create a shared cache with 10-second TTL
40    let cache = Arc::new(CompletionCache::new(Duration::from_secs(10)));
41
42    let app = CommandBuilder::new("kubectl")
43        .short("Kubernetes command-line tool with cached completions")
44        .flag(
45            Flag::new("namespace")
46                .short('n')
47                .usage("The namespace scope for this CLI request")
48                .value_type(FlagType::String)
49                .default(flag_rs::FlagValue::String("default".to_string())),
50        )
51        .subcommand({
52            let cache_clone = Arc::clone(&cache);
53            CommandBuilder::new("get")
54                .short("Display one or many resources")
55                .subcommand({
56                    let cache_for_pods = Arc::clone(&cache_clone);
57                    CommandBuilder::new("pods")
58                        .short("List pods with cached completion")
59                        .arg_completion(move |ctx, prefix| {
60                            let start = Instant::now();
61
62                            // Generate cache key
63                            let cache_key = CompletionCache::make_key(
64                                &["kubectl".to_string(), "get".to_string(), "pods".to_string()],
65                                prefix,
66                                ctx.flags(),
67                            );
68
69                            // Try to get from cache first
70                            if let Some(cached_result) = cache_for_pods.get(&cache_key) {
71                                eprintln!("✓ Cache hit! Completed in {:?}", start.elapsed());
72                                return Ok(cached_result);
73                            }
74
75                            eprintln!("✗ Cache miss - fetching completions...");
76
77                            // Perform expensive operation
78                            let items = expensive_completion(prefix);
79                            let mut result = CompletionResult::new();
80
81                            for item in items {
82                                result = result.add_with_description(
83                                    item.clone(),
84                                    format!(
85                                        "Pod in namespace {}",
86                                        ctx.flag("namespace").unwrap_or(&"default".to_string())
87                                    ),
88                                );
89                            }
90
91                            // Add contextual help
92                            if prefix.is_empty() {
93                                result =
94                                    result.add_help_text("Tip: Start typing to filter pod names");
95                            }
96
97                            // Cache the result
98                            cache_for_pods.put(cache_key, result.clone());
99
100                            eprintln!(
101                                "✓ Completed in {:?} (cached for future use)",
102                                start.elapsed()
103                            );
104                            Ok(result)
105                        })
106                        .build()
107                })
108                .subcommand({
109                    let cache_for_services = Arc::clone(&cache_clone);
110                    CommandBuilder::new("services")
111                        .short("List services with cached completion")
112                        .arg_completion(move |ctx, prefix| {
113                            let cache_key = CompletionCache::make_key(
114                                &[
115                                    "kubectl".to_string(),
116                                    "get".to_string(),
117                                    "services".to_string(),
118                                ],
119                                prefix,
120                                ctx.flags(),
121                            );
122
123                            if let Some(cached) = cache_for_services.get(&cache_key) {
124                                eprintln!("✓ Using cached service completions");
125                                return Ok(cached);
126                            }
127
128                            // Simulate expensive operation
129                            let services = expensive_completion(prefix);
130                            let result = CompletionResult::new().extend(services);
131
132                            cache_for_services.put(cache_key, result.clone());
133                            Ok(result)
134                        })
135                        .build()
136                })
137                .build()
138        })
139        .build();
140
141    println!("=== Cached Completion Demo ===\n");
142    println!("This demo shows how completion caching improves performance.\n");
143    println!("To test completions with caching:");
144    println!("1. Set up bash completion:");
145    println!(
146        "   source <({} completion bash)",
147        std::env::args().next().unwrap_or_default()
148    );
149    println!();
150    println!("2. Try tab completion multiple times:");
151    println!(
152        "   {} get pods n<TAB>     # First time: ~500ms (cache miss)",
153        std::env::args().next().unwrap_or_default()
154    );
155    println!(
156        "   {} get pods n<TAB>     # Second time: <1ms (cache hit!)",
157        std::env::args().next().unwrap_or_default()
158    );
159    println!();
160    println!("3. Different prefixes have separate cache entries:");
161    println!(
162        "   {} get pods r<TAB>     # Different prefix = cache miss",
163        std::env::args().next().unwrap_or_default()
164    );
165    println!();
166    println!("4. Flags affect the cache key:");
167    println!(
168        "   {} -n prod get pods n<TAB>  # Different namespace = different cache",
169        std::env::args().next().unwrap_or_default()
170    );
171    println!();
172    println!("Note: Cache entries expire after 10 seconds in this demo.\n");
173    println!("---\n");
174
175    let args: Vec<String> = std::env::args().skip(1).collect();
176
177    // Handle completion requests
178    if std::env::var("KUBECTL_COMPLETE").is_ok() {
179        // When testing completions, show cache status
180        eprintln!("Cache size: {} entries", cache.size());
181    }
182
183    if let Err(e) = app.execute(args) {
184        eprintln!("{}", e);
185        std::process::exit(1);
186    }
187}
Source

pub fn get(&self, key: &str) -> Option<CompletionResult>

Attempts to get a cached completion result

Returns Some(CompletionResult) if a valid cached entry exists, or None if the entry doesn’t exist or has expired.

Examples found in repository?
examples/cached_completion_demo.rs (line 70)
38fn main() {
39    // Create a shared cache with 10-second TTL
40    let cache = Arc::new(CompletionCache::new(Duration::from_secs(10)));
41
42    let app = CommandBuilder::new("kubectl")
43        .short("Kubernetes command-line tool with cached completions")
44        .flag(
45            Flag::new("namespace")
46                .short('n')
47                .usage("The namespace scope for this CLI request")
48                .value_type(FlagType::String)
49                .default(flag_rs::FlagValue::String("default".to_string())),
50        )
51        .subcommand({
52            let cache_clone = Arc::clone(&cache);
53            CommandBuilder::new("get")
54                .short("Display one or many resources")
55                .subcommand({
56                    let cache_for_pods = Arc::clone(&cache_clone);
57                    CommandBuilder::new("pods")
58                        .short("List pods with cached completion")
59                        .arg_completion(move |ctx, prefix| {
60                            let start = Instant::now();
61
62                            // Generate cache key
63                            let cache_key = CompletionCache::make_key(
64                                &["kubectl".to_string(), "get".to_string(), "pods".to_string()],
65                                prefix,
66                                ctx.flags(),
67                            );
68
69                            // Try to get from cache first
70                            if let Some(cached_result) = cache_for_pods.get(&cache_key) {
71                                eprintln!("✓ Cache hit! Completed in {:?}", start.elapsed());
72                                return Ok(cached_result);
73                            }
74
75                            eprintln!("✗ Cache miss - fetching completions...");
76
77                            // Perform expensive operation
78                            let items = expensive_completion(prefix);
79                            let mut result = CompletionResult::new();
80
81                            for item in items {
82                                result = result.add_with_description(
83                                    item.clone(),
84                                    format!(
85                                        "Pod in namespace {}",
86                                        ctx.flag("namespace").unwrap_or(&"default".to_string())
87                                    ),
88                                );
89                            }
90
91                            // Add contextual help
92                            if prefix.is_empty() {
93                                result =
94                                    result.add_help_text("Tip: Start typing to filter pod names");
95                            }
96
97                            // Cache the result
98                            cache_for_pods.put(cache_key, result.clone());
99
100                            eprintln!(
101                                "✓ Completed in {:?} (cached for future use)",
102                                start.elapsed()
103                            );
104                            Ok(result)
105                        })
106                        .build()
107                })
108                .subcommand({
109                    let cache_for_services = Arc::clone(&cache_clone);
110                    CommandBuilder::new("services")
111                        .short("List services with cached completion")
112                        .arg_completion(move |ctx, prefix| {
113                            let cache_key = CompletionCache::make_key(
114                                &[
115                                    "kubectl".to_string(),
116                                    "get".to_string(),
117                                    "services".to_string(),
118                                ],
119                                prefix,
120                                ctx.flags(),
121                            );
122
123                            if let Some(cached) = cache_for_services.get(&cache_key) {
124                                eprintln!("✓ Using cached service completions");
125                                return Ok(cached);
126                            }
127
128                            // Simulate expensive operation
129                            let services = expensive_completion(prefix);
130                            let result = CompletionResult::new().extend(services);
131
132                            cache_for_services.put(cache_key, result.clone());
133                            Ok(result)
134                        })
135                        .build()
136                })
137                .build()
138        })
139        .build();
140
141    println!("=== Cached Completion Demo ===\n");
142    println!("This demo shows how completion caching improves performance.\n");
143    println!("To test completions with caching:");
144    println!("1. Set up bash completion:");
145    println!(
146        "   source <({} completion bash)",
147        std::env::args().next().unwrap_or_default()
148    );
149    println!();
150    println!("2. Try tab completion multiple times:");
151    println!(
152        "   {} get pods n<TAB>     # First time: ~500ms (cache miss)",
153        std::env::args().next().unwrap_or_default()
154    );
155    println!(
156        "   {} get pods n<TAB>     # Second time: <1ms (cache hit!)",
157        std::env::args().next().unwrap_or_default()
158    );
159    println!();
160    println!("3. Different prefixes have separate cache entries:");
161    println!(
162        "   {} get pods r<TAB>     # Different prefix = cache miss",
163        std::env::args().next().unwrap_or_default()
164    );
165    println!();
166    println!("4. Flags affect the cache key:");
167    println!(
168        "   {} -n prod get pods n<TAB>  # Different namespace = different cache",
169        std::env::args().next().unwrap_or_default()
170    );
171    println!();
172    println!("Note: Cache entries expire after 10 seconds in this demo.\n");
173    println!("---\n");
174
175    let args: Vec<String> = std::env::args().skip(1).collect();
176
177    // Handle completion requests
178    if std::env::var("KUBECTL_COMPLETE").is_ok() {
179        // When testing completions, show cache status
180        eprintln!("Cache size: {} entries", cache.size());
181    }
182
183    if let Err(e) = app.execute(args) {
184        eprintln!("{}", e);
185        std::process::exit(1);
186    }
187}
Source

pub fn put(&self, key: String, result: CompletionResult)

Stores a completion result in the cache

§Arguments
  • key - The cache key
  • result - The completion result to cache
Examples found in repository?
examples/cached_completion_demo.rs (line 98)
38fn main() {
39    // Create a shared cache with 10-second TTL
40    let cache = Arc::new(CompletionCache::new(Duration::from_secs(10)));
41
42    let app = CommandBuilder::new("kubectl")
43        .short("Kubernetes command-line tool with cached completions")
44        .flag(
45            Flag::new("namespace")
46                .short('n')
47                .usage("The namespace scope for this CLI request")
48                .value_type(FlagType::String)
49                .default(flag_rs::FlagValue::String("default".to_string())),
50        )
51        .subcommand({
52            let cache_clone = Arc::clone(&cache);
53            CommandBuilder::new("get")
54                .short("Display one or many resources")
55                .subcommand({
56                    let cache_for_pods = Arc::clone(&cache_clone);
57                    CommandBuilder::new("pods")
58                        .short("List pods with cached completion")
59                        .arg_completion(move |ctx, prefix| {
60                            let start = Instant::now();
61
62                            // Generate cache key
63                            let cache_key = CompletionCache::make_key(
64                                &["kubectl".to_string(), "get".to_string(), "pods".to_string()],
65                                prefix,
66                                ctx.flags(),
67                            );
68
69                            // Try to get from cache first
70                            if let Some(cached_result) = cache_for_pods.get(&cache_key) {
71                                eprintln!("✓ Cache hit! Completed in {:?}", start.elapsed());
72                                return Ok(cached_result);
73                            }
74
75                            eprintln!("✗ Cache miss - fetching completions...");
76
77                            // Perform expensive operation
78                            let items = expensive_completion(prefix);
79                            let mut result = CompletionResult::new();
80
81                            for item in items {
82                                result = result.add_with_description(
83                                    item.clone(),
84                                    format!(
85                                        "Pod in namespace {}",
86                                        ctx.flag("namespace").unwrap_or(&"default".to_string())
87                                    ),
88                                );
89                            }
90
91                            // Add contextual help
92                            if prefix.is_empty() {
93                                result =
94                                    result.add_help_text("Tip: Start typing to filter pod names");
95                            }
96
97                            // Cache the result
98                            cache_for_pods.put(cache_key, result.clone());
99
100                            eprintln!(
101                                "✓ Completed in {:?} (cached for future use)",
102                                start.elapsed()
103                            );
104                            Ok(result)
105                        })
106                        .build()
107                })
108                .subcommand({
109                    let cache_for_services = Arc::clone(&cache_clone);
110                    CommandBuilder::new("services")
111                        .short("List services with cached completion")
112                        .arg_completion(move |ctx, prefix| {
113                            let cache_key = CompletionCache::make_key(
114                                &[
115                                    "kubectl".to_string(),
116                                    "get".to_string(),
117                                    "services".to_string(),
118                                ],
119                                prefix,
120                                ctx.flags(),
121                            );
122
123                            if let Some(cached) = cache_for_services.get(&cache_key) {
124                                eprintln!("✓ Using cached service completions");
125                                return Ok(cached);
126                            }
127
128                            // Simulate expensive operation
129                            let services = expensive_completion(prefix);
130                            let result = CompletionResult::new().extend(services);
131
132                            cache_for_services.put(cache_key, result.clone());
133                            Ok(result)
134                        })
135                        .build()
136                })
137                .build()
138        })
139        .build();
140
141    println!("=== Cached Completion Demo ===\n");
142    println!("This demo shows how completion caching improves performance.\n");
143    println!("To test completions with caching:");
144    println!("1. Set up bash completion:");
145    println!(
146        "   source <({} completion bash)",
147        std::env::args().next().unwrap_or_default()
148    );
149    println!();
150    println!("2. Try tab completion multiple times:");
151    println!(
152        "   {} get pods n<TAB>     # First time: ~500ms (cache miss)",
153        std::env::args().next().unwrap_or_default()
154    );
155    println!(
156        "   {} get pods n<TAB>     # Second time: <1ms (cache hit!)",
157        std::env::args().next().unwrap_or_default()
158    );
159    println!();
160    println!("3. Different prefixes have separate cache entries:");
161    println!(
162        "   {} get pods r<TAB>     # Different prefix = cache miss",
163        std::env::args().next().unwrap_or_default()
164    );
165    println!();
166    println!("4. Flags affect the cache key:");
167    println!(
168        "   {} -n prod get pods n<TAB>  # Different namespace = different cache",
169        std::env::args().next().unwrap_or_default()
170    );
171    println!();
172    println!("Note: Cache entries expire after 10 seconds in this demo.\n");
173    println!("---\n");
174
175    let args: Vec<String> = std::env::args().skip(1).collect();
176
177    // Handle completion requests
178    if std::env::var("KUBECTL_COMPLETE").is_ok() {
179        // When testing completions, show cache status
180        eprintln!("Cache size: {} entries", cache.size());
181    }
182
183    if let Err(e) = app.execute(args) {
184        eprintln!("{}", e);
185        std::process::exit(1);
186    }
187}
Source

pub fn clear(&self)

Clears all cached entries

Source

pub fn size(&self) -> usize

Returns the number of cached entries

Examples found in repository?
examples/cached_completion_demo.rs (line 180)
38fn main() {
39    // Create a shared cache with 10-second TTL
40    let cache = Arc::new(CompletionCache::new(Duration::from_secs(10)));
41
42    let app = CommandBuilder::new("kubectl")
43        .short("Kubernetes command-line tool with cached completions")
44        .flag(
45            Flag::new("namespace")
46                .short('n')
47                .usage("The namespace scope for this CLI request")
48                .value_type(FlagType::String)
49                .default(flag_rs::FlagValue::String("default".to_string())),
50        )
51        .subcommand({
52            let cache_clone = Arc::clone(&cache);
53            CommandBuilder::new("get")
54                .short("Display one or many resources")
55                .subcommand({
56                    let cache_for_pods = Arc::clone(&cache_clone);
57                    CommandBuilder::new("pods")
58                        .short("List pods with cached completion")
59                        .arg_completion(move |ctx, prefix| {
60                            let start = Instant::now();
61
62                            // Generate cache key
63                            let cache_key = CompletionCache::make_key(
64                                &["kubectl".to_string(), "get".to_string(), "pods".to_string()],
65                                prefix,
66                                ctx.flags(),
67                            );
68
69                            // Try to get from cache first
70                            if let Some(cached_result) = cache_for_pods.get(&cache_key) {
71                                eprintln!("✓ Cache hit! Completed in {:?}", start.elapsed());
72                                return Ok(cached_result);
73                            }
74
75                            eprintln!("✗ Cache miss - fetching completions...");
76
77                            // Perform expensive operation
78                            let items = expensive_completion(prefix);
79                            let mut result = CompletionResult::new();
80
81                            for item in items {
82                                result = result.add_with_description(
83                                    item.clone(),
84                                    format!(
85                                        "Pod in namespace {}",
86                                        ctx.flag("namespace").unwrap_or(&"default".to_string())
87                                    ),
88                                );
89                            }
90
91                            // Add contextual help
92                            if prefix.is_empty() {
93                                result =
94                                    result.add_help_text("Tip: Start typing to filter pod names");
95                            }
96
97                            // Cache the result
98                            cache_for_pods.put(cache_key, result.clone());
99
100                            eprintln!(
101                                "✓ Completed in {:?} (cached for future use)",
102                                start.elapsed()
103                            );
104                            Ok(result)
105                        })
106                        .build()
107                })
108                .subcommand({
109                    let cache_for_services = Arc::clone(&cache_clone);
110                    CommandBuilder::new("services")
111                        .short("List services with cached completion")
112                        .arg_completion(move |ctx, prefix| {
113                            let cache_key = CompletionCache::make_key(
114                                &[
115                                    "kubectl".to_string(),
116                                    "get".to_string(),
117                                    "services".to_string(),
118                                ],
119                                prefix,
120                                ctx.flags(),
121                            );
122
123                            if let Some(cached) = cache_for_services.get(&cache_key) {
124                                eprintln!("✓ Using cached service completions");
125                                return Ok(cached);
126                            }
127
128                            // Simulate expensive operation
129                            let services = expensive_completion(prefix);
130                            let result = CompletionResult::new().extend(services);
131
132                            cache_for_services.put(cache_key, result.clone());
133                            Ok(result)
134                        })
135                        .build()
136                })
137                .build()
138        })
139        .build();
140
141    println!("=== Cached Completion Demo ===\n");
142    println!("This demo shows how completion caching improves performance.\n");
143    println!("To test completions with caching:");
144    println!("1. Set up bash completion:");
145    println!(
146        "   source <({} completion bash)",
147        std::env::args().next().unwrap_or_default()
148    );
149    println!();
150    println!("2. Try tab completion multiple times:");
151    println!(
152        "   {} get pods n<TAB>     # First time: ~500ms (cache miss)",
153        std::env::args().next().unwrap_or_default()
154    );
155    println!(
156        "   {} get pods n<TAB>     # Second time: <1ms (cache hit!)",
157        std::env::args().next().unwrap_or_default()
158    );
159    println!();
160    println!("3. Different prefixes have separate cache entries:");
161    println!(
162        "   {} get pods r<TAB>     # Different prefix = cache miss",
163        std::env::args().next().unwrap_or_default()
164    );
165    println!();
166    println!("4. Flags affect the cache key:");
167    println!(
168        "   {} -n prod get pods n<TAB>  # Different namespace = different cache",
169        std::env::args().next().unwrap_or_default()
170    );
171    println!();
172    println!("Note: Cache entries expire after 10 seconds in this demo.\n");
173    println!("---\n");
174
175    let args: Vec<String> = std::env::args().skip(1).collect();
176
177    // Handle completion requests
178    if std::env::var("KUBECTL_COMPLETE").is_ok() {
179        // When testing completions, show cache status
180        eprintln!("Cache size: {} entries", cache.size());
181    }
182
183    if let Err(e) = app.execute(args) {
184        eprintln!("{}", e);
185        std::process::exit(1);
186    }
187}

Trait Implementations§

Source§

impl Default for CompletionCache

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.

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