mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Replace some &String with &Path
This commit is contained in:
committed by
Levente Kurusa
parent
3413b7d847
commit
751dbc7244
@@ -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<P: AsRef<Path>>(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<P: AsRef<Path>>(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::<Vec<_>>();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user