Skip to content

Commit dd621ea

Browse files
tecywiz121levex
authored andcommitted
Replace &String with &str
1 parent 751dbc7 commit dd621ea

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/cpuset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl CpuSetController {
309309
///
310310
/// Syntax is a comma separated list of CPUs, with an additional extension that ranges can
311311
/// be represented via dashes.
312-
pub fn set_cpus(&self, cpus: &String) -> Result<()> {
312+
pub fn set_cpus(&self, cpus: &str) -> Result<()> {
313313
self.open_path("cpuset.cpus", true).and_then(|mut file| {
314314
file.write_all(cpus.as_ref())
315315
.map_err(|e| Error::with_cause(WriteFailed, e))
@@ -319,7 +319,7 @@ impl CpuSetController {
319319
/// Set the memory nodes that the tasks in this control group can use.
320320
///
321321
/// Syntax is the same as with `set_cpus()`.
322-
pub fn set_mems(&self, mems: &String) -> Result<()> {
322+
pub fn set_mems(&self, mems: &str) -> Result<()> {
323323
self.open_path("cpuset.mems", true).and_then(|mut file| {
324324
file.write_all(mems.as_ref())
325325
.map_err(|e| Error::with_cause(WriteFailed, e))

src/devices.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl DevicePermissions {
9494
}
9595

9696
/// Checks whether the string is a valid descriptor of DevicePermissions.
97-
pub fn is_valid(s: &String) -> bool {
97+
pub fn is_valid(s: &str) -> bool {
9898
if s == "" {
9999
return false;
100100
}
@@ -116,18 +116,18 @@ impl DevicePermissions {
116116
}
117117

118118
/// Convert a string into DevicePermissions.
119-
///
120-
/// NOTE: This function makes no effort in verifying the String.
121-
pub fn from_string(s: &String) -> Vec<DevicePermissions> {
119+
pub fn from_str(s: &str) -> Result<Vec<DevicePermissions>> {
122120
let mut v = Vec::new();
123121
if s == "" {
124-
return v;
122+
return Ok(v);
125123
}
126124
for e in s.chars() {
127-
v.push(DevicePermissions::from_char(e).unwrap());
125+
let perm = DevicePermissions::from_char(e)
126+
.ok_or_else(|| Error::new(ParseError))?;
127+
v.push(perm);
128128
}
129129

130-
v
130+
Ok(v)
131131
}
132132
}
133133

@@ -285,7 +285,7 @@ impl DevicesController {
285285
acc, ls, devtype, major, minor, &ls[3]);
286286
Err(Error::new(ParseError))
287287
} else {
288-
let access = DevicePermissions::from_string(&ls[3]);
288+
let access = DevicePermissions::from_str(&ls[3])?;
289289
let mut acc = acc.unwrap();
290290
acc.push(DeviceResource {
291291
allow: true,

src/hugetlb.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,34 @@ impl HugeTlbController {
9494
}
9595

9696
/// Whether the system supports `hugetlb_size` hugepages.
97-
pub fn size_supported(&self, _hugetlb_size: String) -> bool {
97+
pub fn size_supported(&self, _hugetlb_size: &str) -> bool {
9898
// TODO
9999
true
100100
}
101101

102102
/// Check how many times has the limit of `hugetlb_size` hugepages been hit.
103-
pub fn failcnt(&self, hugetlb_size: &String) -> Result<u64> {
103+
pub fn failcnt(&self, hugetlb_size: &str) -> Result<u64> {
104104
self.open_path(&format!("hugetlb.{}.failcnt", hugetlb_size), false)
105105
.and_then(read_u64_from)
106106
}
107107

108108
/// Get the limit (in bytes) of how much memory can be backed by hugepages of a certain size
109109
/// (`hugetlb_size`).
110-
pub fn limit_in_bytes(&self, hugetlb_size: &String) -> Result<u64> {
110+
pub fn limit_in_bytes(&self, hugetlb_size: &str) -> Result<u64> {
111111
self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), false)
112112
.and_then(read_u64_from)
113113
}
114114

115115
/// Get the current usage of memory that is backed by hugepages of a certain size
116116
/// (`hugetlb_size`).
117-
pub fn usage_in_bytes(&self, hugetlb_size: &String) -> Result<u64> {
117+
pub fn usage_in_bytes(&self, hugetlb_size: &str) -> Result<u64> {
118118
self.open_path(&format!("hugetlb.{}.usage_in_bytes", hugetlb_size), false)
119119
.and_then(read_u64_from)
120120
}
121121

122122
/// Get the maximum observed usage of memory that is backed by hugepages of a certain size
123123
/// (`hugetlb_size`).
124-
pub fn max_usage_in_bytes(&self, hugetlb_size: &String) -> Result<u64> {
124+
pub fn max_usage_in_bytes(&self, hugetlb_size: &str) -> Result<u64> {
125125
self.open_path(
126126
&format!("hugetlb.{}.max_usage_in_bytes", hugetlb_size),
127127
false,
@@ -130,7 +130,7 @@ impl HugeTlbController {
130130

131131
/// Set the limit (in bytes) of how much memory can be backed by hugepages of a certain size
132132
/// (`hugetlb_size`).
133-
pub fn set_limit_in_bytes(&self, hugetlb_size: &String, limit: u64) -> Result<()> {
133+
pub fn set_limit_in_bytes(&self, hugetlb_size: &str, limit: u64) -> Result<()> {
134134
self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), true)
135135
.and_then(|mut file| {
136136
file.write_all(limit.to_string().as_ref())

src/net_prio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl NetPrioController {
133133
}
134134

135135
/// Set the priority of the network traffic on `eif` to be `prio`.
136-
pub fn set_if_prio(&self, eif: &String, prio: u64) -> Result<()> {
136+
pub fn set_if_prio(&self, eif: &str, prio: u64) -> Result<()> {
137137
self.open_path("net_prio.ifpriomap", true)
138138
.and_then(|mut file| {
139139
file.write_all(format!("{} {}", eif, prio).as_ref())

src/rdma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl RdmaController {
8686
}
8787

8888
/// Set a maximum usage for each RDMA/IB resource.
89-
pub fn set_max(&self, max: &String) -> Result<()> {
89+
pub fn set_max(&self, max: &str) -> Result<()> {
9090
self.open_path("rdma.max", true).and_then(|mut file| {
9191
file.write_all(max.as_ref())
9292
.map_err(|e| Error::with_cause(WriteFailed, e))

0 commit comments

Comments
 (0)