diff --git a/src/cpuset.rs b/src/cpuset.rs index 55a50a9..1d0ed45 100644 --- a/src/cpuset.rs +++ b/src/cpuset.rs @@ -309,7 +309,7 @@ impl CpuSetController { /// /// Syntax is a comma separated list of CPUs, with an additional extension that ranges can /// be represented via dashes. - pub fn set_cpus(&self, cpus: &String) -> Result<()> { + pub fn set_cpus(&self, cpus: &str) -> Result<()> { self.open_path("cpuset.cpus", true).and_then(|mut file| { file.write_all(cpus.as_ref()) .map_err(|e| Error::with_cause(WriteFailed, e)) @@ -319,7 +319,7 @@ impl CpuSetController { /// Set the memory nodes that the tasks in this control group can use. /// /// Syntax is the same as with `set_cpus()`. - pub fn set_mems(&self, mems: &String) -> Result<()> { + pub fn set_mems(&self, mems: &str) -> Result<()> { self.open_path("cpuset.mems", true).and_then(|mut file| { file.write_all(mems.as_ref()) .map_err(|e| Error::with_cause(WriteFailed, e)) diff --git a/src/devices.rs b/src/devices.rs index 355ea63..e3371f8 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -94,7 +94,7 @@ impl DevicePermissions { } /// Checks whether the string is a valid descriptor of DevicePermissions. - pub fn is_valid(s: &String) -> bool { + pub fn is_valid(s: &str) -> bool { if s == "" { return false; } @@ -116,18 +116,18 @@ impl DevicePermissions { } /// Convert a string into DevicePermissions. - /// - /// NOTE: This function makes no effort in verifying the String. - pub fn from_string(s: &String) -> Vec { + pub fn from_str(s: &str) -> Result> { let mut v = Vec::new(); if s == "" { - return v; + return Ok(v); } for e in s.chars() { - v.push(DevicePermissions::from_char(e).unwrap()); + let perm = DevicePermissions::from_char(e) + .ok_or_else(|| Error::new(ParseError))?; + v.push(perm); } - v + Ok(v) } } @@ -285,7 +285,7 @@ impl DevicesController { acc, ls, devtype, major, minor, &ls[3]); Err(Error::new(ParseError)) } else { - let access = DevicePermissions::from_string(&ls[3]); + let access = DevicePermissions::from_str(&ls[3])?; let mut acc = acc.unwrap(); acc.push(DeviceResource { allow: true, diff --git a/src/hugetlb.rs b/src/hugetlb.rs index ee5cbf4..db714d1 100644 --- a/src/hugetlb.rs +++ b/src/hugetlb.rs @@ -94,34 +94,34 @@ impl HugeTlbController { } /// Whether the system supports `hugetlb_size` hugepages. - pub fn size_supported(&self, _hugetlb_size: String) -> bool { + pub fn size_supported(&self, _hugetlb_size: &str) -> bool { // TODO true } /// Check how many times has the limit of `hugetlb_size` hugepages been hit. - pub fn failcnt(&self, hugetlb_size: &String) -> Result { + pub fn failcnt(&self, hugetlb_size: &str) -> Result { self.open_path(&format!("hugetlb.{}.failcnt", hugetlb_size), false) .and_then(read_u64_from) } /// Get the limit (in bytes) of how much memory can be backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn limit_in_bytes(&self, hugetlb_size: &String) -> Result { + pub fn limit_in_bytes(&self, hugetlb_size: &str) -> Result { self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), false) .and_then(read_u64_from) } /// Get the current usage of memory that is backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn usage_in_bytes(&self, hugetlb_size: &String) -> Result { + pub fn usage_in_bytes(&self, hugetlb_size: &str) -> Result { self.open_path(&format!("hugetlb.{}.usage_in_bytes", hugetlb_size), false) .and_then(read_u64_from) } /// Get the maximum observed usage of memory that is backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn max_usage_in_bytes(&self, hugetlb_size: &String) -> Result { + pub fn max_usage_in_bytes(&self, hugetlb_size: &str) -> Result { self.open_path( &format!("hugetlb.{}.max_usage_in_bytes", hugetlb_size), false, @@ -130,7 +130,7 @@ impl HugeTlbController { /// Set the limit (in bytes) of how much memory can be backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn set_limit_in_bytes(&self, hugetlb_size: &String, limit: u64) -> Result<()> { + pub fn set_limit_in_bytes(&self, hugetlb_size: &str, limit: u64) -> Result<()> { self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), true) .and_then(|mut file| { file.write_all(limit.to_string().as_ref()) diff --git a/src/net_prio.rs b/src/net_prio.rs index 4bd2672..9fcb428 100644 --- a/src/net_prio.rs +++ b/src/net_prio.rs @@ -133,7 +133,7 @@ impl NetPrioController { } /// Set the priority of the network traffic on `eif` to be `prio`. - pub fn set_if_prio(&self, eif: &String, prio: u64) -> Result<()> { + pub fn set_if_prio(&self, eif: &str, prio: u64) -> Result<()> { self.open_path("net_prio.ifpriomap", true) .and_then(|mut file| { file.write_all(format!("{} {}", eif, prio).as_ref()) diff --git a/src/rdma.rs b/src/rdma.rs index 5c8879e..ea4b078 100644 --- a/src/rdma.rs +++ b/src/rdma.rs @@ -86,7 +86,7 @@ impl RdmaController { } /// Set a maximum usage for each RDMA/IB resource. - pub fn set_max(&self, max: &String) -> Result<()> { + pub fn set_max(&self, max: &str) -> Result<()> { self.open_path("rdma.max", true).and_then(|mut file| { file.write_all(max.as_ref()) .map_err(|e| Error::with_cause(WriteFailed, e))