Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ pub fn list_resources(
// if description, tags, or write_table is specified, pull resource manifest if it exists
if let Some(ref manifest) = resource.manifest {
// if description is specified, skip if resource description does not contain it
if description.is_some() && (manifest.description.is_none() | !manifest.description.clone().unwrap_or_default().to_lowercase().contains(&description.unwrap_or(&String::new()).to_lowercase())) {
if description.is_some() && (manifest.description.is_none() | !manifest.description.as_ref().unwrap_or(&String::new()).to_lowercase().contains(&description.unwrap_or(&String::new()).to_lowercase())) {
continue;
Comment on lines +822 to 823
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the bitwise OR operator (|) on booleans, which forces evaluation of both sides and defeats short-circuiting (and any perf win from avoiding clones). Use || here, and consider restructuring to avoid repeated to_lowercase() allocations (e.g., compute the lowercased filter once when description is Some).

Suggested change
if description.is_some() && (manifest.description.is_none() | !manifest.description.as_ref().unwrap_or(&String::new()).to_lowercase().contains(&description.unwrap_or(&String::new()).to_lowercase())) {
continue;
if let Some(description_filter) = description {
let description_filter_lower = description_filter.to_lowercase();
let matches_description = manifest.description
.as_ref()
.map(|resource_description| resource_description.to_lowercase().contains(&description_filter_lower))
.unwrap_or(false);
if !matches_description {
continue;
}

Copilot uses AI. Check for mistakes.
}

Expand Down
6 changes: 3 additions & 3 deletions dsc/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
// command-line args override setting value, but not policy
if !policy_is_used {
if let Some(v) = trace_level_arg {
tracing_setting.level = v.clone();
tracing_setting.level = *v;
}
if let Some(v) = trace_format_arg {
tracing_setting.format = v.clone();
tracing_setting.format = *v;
Comment on lines 369 to +373
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TraceLevel and TraceFormat only derive Clone (not Copy), so assigning from &TraceLevel / &TraceFormat with *v won’t compile. Keep v.clone() here, or add Copy to the enum definitions if changing the public API is acceptable.

Copilot uses AI. Check for mistakes.
}
}

Expand Down Expand Up @@ -443,7 +443,7 @@ pub fn get_input(input: Option<&String>, file: Option<&String>) -> String {
error!("{}", t!("util.inputIsFile"));
exit(EXIT_INVALID_INPUT);
}
input.clone()
input.to_owned()
} else if let Some(path) = file {
debug!("{} {path}", t!("util.readingInputFromFile"));
// check if need to read from STDIN
Expand Down
64 changes: 32 additions & 32 deletions lib/dsc-lib-jsonschema/src/schema_utility_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,26 +680,26 @@ pub trait SchemaUtilityExtensions {

//************************ $id keyword functions *************************//
/// Retrieves the `$id` values for any entries in the `$defs` keyword.
///
///
/// A compound schema resource document, also called a "bundled schema", includes referenced
/// schema resources in the `$defs` keyword. A schema resource always defines the `$id` keyword.
///
///
/// This method retrieves those IDs and returns a hashset containing the unique values.
///
///
/// Optionally, you can recursively search for schema resource IDs to handle cases where the
/// a bundled schema resource may itself have bundled resources.
///
///
/// If the schema doesn't have any bundled schema resources, this method returns an empty
/// hashset.
///
///
/// # Examples
///
///
/// This example demonstrates the difference between invoking the method for the top-level
/// only and recursively returning nested bundled schema resources.
///
///
/// ```rust
/// use std::collections::HashSet;
///
///
/// use schemars::json_schema;
/// use serde_json::json;
/// use dsc_lib_jsonschema::schema_utility_extensions::SchemaUtilityExtensions;
Expand All @@ -725,7 +725,7 @@ pub trait SchemaUtilityExtensions {
/// }
/// }
/// });
///
///
/// let non_recursive_result: HashSet<&str> = [
/// "https://contoso.com/schemas/example/string.json",
/// "https://contoso.com/schemas/example/object.json"
Expand All @@ -734,7 +734,7 @@ pub trait SchemaUtilityExtensions {
/// schema.get_bundled_schema_resource_ids(false),
/// non_recursive_result
/// );
///
///
/// let recursive_result: HashSet<&str> = [
/// "https://contoso.com/schemas/example/string.json",
/// "https://contoso.com/schemas/example/object.json",
Expand Down Expand Up @@ -1474,20 +1474,20 @@ pub trait SchemaUtilityExtensions {
//************************ $ref keyword functions ************************//
/// Retrieves the value for every `$ref` keyword from the [`Schema`] as a [`HashSet`] of
/// unique values.
///
///
///
///
/// This method recurses through a given schema for the `$ref` keyword and inserts the value
/// into a hashset to return. If the schema doesn't define any references, this method returns
/// an empty hashset.
///
///
/// # Examples
///
///
/// This example shows how the method returns a unique set of references by recursively
/// searching the schema for the `$ref` keyword.
///
///
/// ```rust
/// use std::collections::HashSet;
///
///
/// use schemars::json_schema;
/// use dsc_lib_jsonschema::schema_utility_extensions::SchemaUtilityExtensions;
///
Expand All @@ -1499,12 +1499,12 @@ pub trait SchemaUtilityExtensions {
/// "age": { "$ref": "/schemas/example/properties/age.json" },
/// },
/// });
///
///
/// let references: HashSet<&str> = [
/// "/schemas/example/properties/name.json",
/// "/schemas/example/properties/age.json"
/// ].into();
///
///
/// assert_eq!(
/// schema.get_references(),
/// references
Expand Down Expand Up @@ -1559,7 +1559,7 @@ pub trait SchemaUtilityExtensions {
/// "nestedBar": { "$ref": "#/$defs/bar" },
/// },
/// },
///
///
/// },
/// });
///
Expand All @@ -1576,17 +1576,17 @@ pub trait SchemaUtilityExtensions {
fn get_references_to_bundled_schema_resource(&self, resource_id: &str) -> HashSet<&str>;
/// Searches the schema for instances of the `$ref` keyword defined as a
/// given value and replaces each instance with a new value.
///
///
/// This method simplifies replacing references programmatically, especially
/// for converting references to use the canonical ID of a bundled schema
/// resource.
///
///
/// # Examples
///
///
/// This example replaces the reference to `#/$defs/name.json` with the
/// canonical ID URI for the referenced schema resource, which is bundled
/// in the schema.
///
///
/// ```rust
/// use schemars::json_schema;
/// use dsc_lib_jsonschema::schema_utility_extensions::SchemaUtilityExtensions;
Expand All @@ -1604,34 +1604,34 @@ pub trait SchemaUtilityExtensions {
/// }
/// }
/// });
///
///
/// schema.replace_references(
/// "#/$defs/name",
/// "https://contoso.com/schemas/example/properties/name.json"
/// );
///
///
/// assert_eq!(
/// schema.get_references().into_iter().nth(0).unwrap(),
/// "https://contoso.com/schemas/example/properties/name.json"
/// );
/// ```
fn replace_references(&mut self, find_value: &str, new_value: &str);
/// Checks whether a given reference maps to a bundled schema resource.
///
///
/// This method takes the value of a `$ref` keyword and searches for a matching entry in the
/// `$defs` keyword. The method returns `true` if the reference resolves to an entry in
/// `$defs` and otherwise false.
///
///
/// The reference can be any of the following:
///
/// - A URI identifier fragment, like `#/$defs/foo`
/// - An absolute URL for the referenced schema, like `https://contoso.com/schemas/example.json`
/// - A site-relative URL for the referenced schema, like `/schemas/example.json`. The function
/// can only resolve site-relative URLs when the schema itself defines `$id` with an absolute
/// URL, because it uses the current schema's `$id` as the base URL.
///
///
/// # Examples
///
///
/// ```rust
/// use schemars::json_schema;
/// use dsc_lib_jsonschema::schema_utility_extensions::SchemaUtilityExtensions;
Expand All @@ -1645,7 +1645,7 @@ pub trait SchemaUtilityExtensions {
/// }
/// }
/// });
///
///
/// // Resolving reference as pointer
/// assert_eq!(schema.reference_is_for_bundled_resource("#/$defs/name"), true);
/// // Resolving reference as site-relative URI
Expand Down Expand Up @@ -1991,7 +1991,7 @@ impl SchemaUtilityExtensions for Schema {
if k.as_str() == old_key {
(new_key.to_string(), v.clone())
} else {
(k.clone(), v.clone())
(std::mem::take(k), v.clone())
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::mem::take(k) requires k: &mut String, but when iterating a serde_json::Map you don’t get mutable access to keys. This should be a compile error; prefer keeping k.clone() or rebuild the map by taking/replacing the whole defs map and iterating by value.

Suggested change
(std::mem::take(k), v.clone())
(k.clone(), v.clone())

Copilot uses AI. Check for mistakes.
}
}).collect();
}
Expand Down Expand Up @@ -2148,7 +2148,7 @@ impl SchemaUtilityExtensions for Schema {
let Some(def_key) = self.get_bundled_schema_resource_defs_key(resource_id) else {
return HashSet::new();
};

let matching_references = &mut vec![
format!("#/$defs/{def_key}"),
resource_id.to_string(),
Expand Down
6 changes: 4 additions & 2 deletions lib/dsc-lib-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ impl RegistryHelper {
///
/// * `RegistryError` - The error that occurred.
pub fn new_from_json(config: &str) -> Result<Self, RegistryError> {
let registry: Registry = match serde_json::from_str(config) {
let mut registry: Registry = match serde_json::from_str(config) {
Ok(config) => config,
Err(e) => return Err(RegistryError::Json(e)),
};
let key_path = registry.key_path.clone();
let key_path = std::mem::take(&mut registry.key_path);
let (hive, subkey) = get_hive_from_path(&key_path)?;

// Restore the key_path since we moved it out
registry.key_path = key_path;
Comment on lines 36 to +41
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::mem::take(&mut registry.key_path) and then restoring it adds mutation/complexity. You can avoid the clone by borrowing registry.key_path.as_str() to compute (hive, subkey) before moving registry into Self { config: registry, ... }.

Copilot uses AI. Check for mistakes.
Ok(
Self {
config: registry,
Expand Down
14 changes: 7 additions & 7 deletions lib/dsc-lib/src/dscresources/dscresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl DscResource {
}
}

fn create_config_for_adapter(self, adapter: &FullyQualifiedTypeName, input: &str) -> Result<Configurator, DscError> {
fn create_config_for_adapter(&self, adapter: &FullyQualifiedTypeName, input: &str) -> Result<Configurator, DscError> {
// create new configuration with adapter and use this as the resource
let mut configuration = Configuration::new();
let mut property_map = Map::new();
Expand All @@ -144,7 +144,7 @@ impl DscResource {
}

fn invoke_get_with_adapter(&self, adapter: &FullyQualifiedTypeName, target_resource: &DscResource, filter: &str) -> Result<GetResult, DscError> {
let mut configurator = self.clone().create_config_for_adapter(adapter, filter)?;
let mut configurator = self.create_config_for_adapter(adapter, filter)?;
let mut adapter = Self::get_adapter_resource(&mut configurator, adapter)?;
if get_adapter_input_kind(&adapter)? == AdapterInputKind::Single {
adapter.target_resource = Some(Box::new(target_resource.clone()));
Expand All @@ -168,7 +168,7 @@ impl DscResource {
}

fn invoke_set_with_adapter(&self, adapter: &FullyQualifiedTypeName, target_resource: &DscResource, desired: &str, skip_test: bool, execution_type: &ExecutionKind) -> Result<SetResult, DscError> {
let mut configurator = self.clone().create_config_for_adapter(adapter, desired)?;
let mut configurator = self.create_config_for_adapter(adapter, desired)?;
let mut adapter = Self::get_adapter_resource(&mut configurator, adapter)?;
if get_adapter_input_kind(&adapter)? == AdapterInputKind::Single {
adapter.target_resource = Some(Box::new(target_resource.clone()));
Expand Down Expand Up @@ -201,7 +201,7 @@ impl DscResource {
}

fn invoke_test_with_adapter(&self, adapter: &FullyQualifiedTypeName, target_resource: &DscResource, expected: &str) -> Result<TestResult, DscError> {
let mut configurator = self.clone().create_config_for_adapter(adapter, expected)?;
let mut configurator = self.create_config_for_adapter(adapter, expected)?;
let mut adapter = Self::get_adapter_resource(&mut configurator, adapter)?;
if get_adapter_input_kind(&adapter)? == AdapterInputKind::Single {
adapter.target_resource = Some(Box::new(target_resource.clone()));
Expand Down Expand Up @@ -235,7 +235,7 @@ impl DscResource {
}

fn invoke_delete_with_adapter(&self, adapter: &FullyQualifiedTypeName, target_resource: &DscResource, filter: &str, execution_type: &ExecutionKind) -> Result<DeleteResultKind, DscError> {
let mut configurator = self.clone().create_config_for_adapter(adapter, filter)?;
let mut configurator = self.create_config_for_adapter(adapter, filter)?;
let mut adapter = Self::get_adapter_resource(&mut configurator, adapter)?;
if get_adapter_input_kind(&adapter)? == AdapterInputKind::Single {
if adapter.capabilities.contains(&Capability::Delete) {
Expand All @@ -250,7 +250,7 @@ impl DscResource {
}

fn invoke_export_with_adapter(&self, adapter: &FullyQualifiedTypeName, target_resource: &DscResource,input: &str) -> Result<ExportResult, DscError> {
let mut configurator = self.clone().create_config_for_adapter(adapter, input)?;
let mut configurator = self.create_config_for_adapter(adapter, input)?;
let mut adapter = Self::get_adapter_resource(&mut configurator, adapter)?;
if get_adapter_input_kind(&adapter)? == AdapterInputKind::Single {
adapter.target_resource = Some(Box::new(target_resource.clone()));
Expand Down Expand Up @@ -280,7 +280,7 @@ impl DscResource {
}

fn invoke_schema_with_adapter(&self, adapter: &FullyQualifiedTypeName, target_resource: &DscResource) -> Result<String, DscError> {
let mut configurator = self.clone().create_config_for_adapter(adapter, "")?;
let mut configurator = self.create_config_for_adapter(adapter, "")?;
let mut adapter = Self::get_adapter_resource(&mut configurator, adapter)?;
if get_adapter_input_kind(&adapter)? == AdapterInputKind::Single {
adapter.target_resource = Some(Box::new(target_resource.clone()));
Expand Down
20 changes: 10 additions & 10 deletions lib/dsc-lib/src/functions/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ impl Function for Intersection {

fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
debug!("{}", t!("functions.intersection.invoked"));

if let Some(first_array) = args[0].as_array() {
let mut result = Vec::new();

for item in first_array {
let mut found_in_all = true;

for arg in &args[1..] {
if let Some(array) = arg.as_array() {
if !array.contains(item) {
Expand All @@ -47,21 +47,21 @@ impl Function for Intersection {
return Err(DscError::Parser(t!("functions.intersection.invalidArgType").to_string()));
}
}

if found_in_all && !result.contains(item) {
result.push(item.clone());
}
}

return Ok(Value::Array(result));
}

if let Some(first_object) = args[0].as_object() {
let mut result = Map::new();

for (key, value) in first_object {
let mut found_in_all = true;

for arg in &args[1..] {
if let Some(object) = arg.as_object() {
if let Some(other_value) = object.get(key) {
Expand All @@ -77,12 +77,12 @@ impl Function for Intersection {
return Err(DscError::Parser(t!("functions.intersection.invalidArgType").to_string()));
}
}

if found_in_all {
result.insert(key.clone(), value.clone());
result.insert(key.to_string(), value.clone());
}
}

return Ok(Value::Object(result));
}

Expand Down
Loading
Loading