diff --git a/src/cgroup.rs b/src/cgroup.rs index 020fca1..9fae5ca 100644 --- a/src/cgroup.rs +++ b/src/cgroup.rs @@ -5,6 +5,7 @@ use error::*; use {CgroupPid, ControllIdentifier, Controller, Hierarchy, Resources, Subsystem}; use std::convert::From; +use std::path::Path; /// A control group is the central structure to this crate. /// @@ -40,7 +41,7 @@ impl<'b> Cgroup<'b> { /// /// Note that if the handle goes out of scope and is dropped, the control group is _not_ /// destroyed. - pub fn new(hier: &Hierarchy, path: String) -> Cgroup { + pub fn new>(hier: &Hierarchy, path: P) -> Cgroup { let cg = Cgroup::load(hier, path); cg.create(); cg @@ -53,12 +54,13 @@ impl<'b> Cgroup<'b> { /// /// Note that if the handle goes out of scope and is dropped, the control group is _not_ /// destroyed. - pub fn load(hier: &Hierarchy, path: String) -> Cgroup { + pub fn load>(hier: &Hierarchy, path: P) -> Cgroup { + let path = path.as_ref(); let mut subsystems = hier.subsystems(); - if path != "" { + if path.as_os_str() != "" { subsystems = subsystems .into_iter() - .map(|x| x.enter(&path)) + .map(|x| x.enter(path)) .collect::>(); } diff --git a/src/lib.rs b/src/lib.rs index 1d00503..5983bf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ extern crate log; use std::fs::File; use std::io::{BufRead, BufReader, Write}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; pub mod blkio; pub mod cgroup; @@ -492,7 +492,7 @@ impl<'a> From<&'a std::process::Child> for CgroupPid { } impl Subsystem { - fn enter(self, path: &String) -> Self { + fn enter(self, path: &Path) -> Self { match self { Subsystem::Pid(cont) => Subsystem::Pid({ let mut c = cont.clone();