From 56547858b147cdca884658a8a342f0c68e4e41a5 Mon Sep 17 00:00:00 2001 From: Ollrogge Date: Wed, 18 Feb 2026 16:25:06 +0000 Subject: [PATCH] Fix code sample in README --- README.md | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 81ff297..c7e27a4 100644 --- a/README.md +++ b/README.md @@ -9,38 +9,43 @@ Native Rust library for managing Linux control groups. Supports both cgroups v1 ### Create a control group using the builder pattern ```rust -use cgroups_rs::*; -use cgroups_rs::cgroup_builder::*; - -// Acquire a handle for the cgroup hierarchy. -let hier = cgroups_rs::hierarchies::auto(); - -// Use the builder pattern (see the documentation to create the control group) -// -// This creates a control group named "example" in the V1 hierarchy. +use cgroups_rs::{ + CgroupPid, + fs::{Cgroup, Controller, cgroup_builder::*, cpu::CpuController, hierarchies}, +}; + +fn main() { + // Acquire a handle for the cgroup hierarchy. + let hier = hierarchies::auto(); + + // Use the builder pattern (see the documentation to create the control group) + // + // This creates a control group named "example" in the V1 hierarchy. let cg: Cgroup = CgroupBuilder::new("example") .cpu() .shares(85) .done() - .build(hier); + .build(hier) + .unwrap(); -// Now `cg` is a control group that gets 85% of the CPU time in relative to -// other control groups. + // Now `cg` is a control group that gets 85% of the CPU time in relative to + // other control groups. -// Get a handle to the CPU controller. -let cpus: &cgroups_rs::cpu::CpuController = cg.controller_of().unwrap(); -cpus.add_task(&CgroupPid::from(1234u64)); + // Get a handle to the CPU controller. + let cpus: &CpuController = cg.controller_of().unwrap(); + cpus.add_task(&CgroupPid::from(1234u64)).unwrap(); -// [...] + // [...] -// Finally, clean up and delete the control group. -cg.delete(); + // Finally, clean up and delete the control group. + cg.delete().unwrap(); -// Note that `Cgroup` does not implement `Drop` and therefore when the -// structure is dropped, the Cgroup will stay around. This is because, later -// you can then re-create the `Cgroup` using `load()`. We aren't too set on -// this behavior, so it might change in the feature. Rest assured, it will be a -// major version change. + // Note that `Cgroup` does not implement `Drop` and therefore when the + // structure is dropped, the Cgroup will stay around. This is because, later + // you can then re-create the `Cgroup` using `load()`. We aren't too set on + // this behavior, so it might change in the feature. Rest assured, it will be a + // major version change. +} ``` ## Disclaimer