Skip to content

Commit 9c51dc6

Browse files
Jonathan Woollett-LightJonathanWoollett-Light
authored andcommitted
refactor: Replace redundant serde_json::from_slice(x.as_bytes())
Replaces instances of `serde_json::from_slice(x.as_bytes())` with the equivalent but simpler `serde_json::from_str(&x)`. Signed-off-by: Jonathan Woollett-Light <[email protected]>
1 parent 1a2c6ad commit 9c51dc6

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/cpu-template-helper/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ mod tests {
319319
microcode_version: "sample_microcode_version".to_string(),
320320
bios_version: "sample_bios_version".to_string(),
321321
bios_revision: "sample_bios_revision".to_string(),
322-
guest_cpu_config: serde_json::from_slice(SAMPLE_MODIFIERS.as_bytes()).unwrap(),
322+
guest_cpu_config: serde_json::from_str(SAMPLE_MODIFIERS).unwrap(),
323323
};
324324
let file = TempFile::new().unwrap();
325325
file.as_file()

src/vmm/src/resources.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl VmResources {
135135
mmds_size_limit: usize,
136136
metadata_json: Option<&str>,
137137
) -> Result<Self, ResourcesError> {
138-
let vmm_config: VmmConfig = serde_json::from_slice::<VmmConfig>(config_json.as_bytes())?;
138+
let vmm_config = serde_json::from_str::<VmmConfig>(config_json)?;
139139

140140
if let Some(logger) = vmm_config.logger {
141141
init_logger(logger, instance_info)?;
@@ -1186,8 +1186,7 @@ mod tests {
11861186
)
11871187
.unwrap();
11881188

1189-
let initial_vmm_config =
1190-
serde_json::from_slice::<VmmConfig>(json.as_bytes()).unwrap();
1189+
let initial_vmm_config = serde_json::from_str::<VmmConfig>(&json).unwrap();
11911190
let vmm_config: VmmConfig = (&resources).into();
11921191
assert_eq!(initial_vmm_config, vmm_config);
11931192
}
@@ -1202,8 +1201,7 @@ mod tests {
12021201
)
12031202
.unwrap();
12041203

1205-
let initial_vmm_config =
1206-
serde_json::from_slice::<VmmConfig>(json.as_bytes()).unwrap();
1204+
let initial_vmm_config = serde_json::from_str::<VmmConfig>(&json).unwrap();
12071205
let vmm_config: VmmConfig = (&resources).into();
12081206
assert_eq!(initial_vmm_config, vmm_config);
12091207
}
@@ -1263,7 +1261,7 @@ mod tests {
12631261
)
12641262
.unwrap();
12651263

1266-
let initial_vmm_config = serde_json::from_slice::<VmmConfig>(json.as_bytes()).unwrap();
1264+
let initial_vmm_config = serde_json::from_str::<VmmConfig>(&json).unwrap();
12671265
let vmm_config: VmmConfig = (&resources).into();
12681266
assert_eq!(initial_vmm_config, vmm_config);
12691267
}
@@ -1322,7 +1320,7 @@ mod tests {
13221320
)
13231321
.unwrap();
13241322

1325-
let initial_vmm_config = serde_json::from_slice::<VmmConfig>(json.as_bytes()).unwrap();
1323+
let initial_vmm_config = serde_json::from_str::<VmmConfig>(&json).unwrap();
13261324
let vmm_config: VmmConfig = (&resources).into();
13271325
assert_eq!(initial_vmm_config, vmm_config);
13281326
}

0 commit comments

Comments
 (0)