You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: sched_agent.rs
    path of file: ./repos/occlum/src/libos/src/sched
    
    the code of the file until where you have to start completion: //! SchedAgent manages the CPU scheduler settings for a thread.
//!
//! # Scheduler Settings
//!
//! Currently, the only scheduler setting that SchedAgent can access and update
//! is the CPU affinity of a thread. Other settings will be added in the future.
//!
//! # The Two Modes: Attached vs Detached
//!
//! SchedAgent works in one of the two modes: the attached mode and the detached
//! mode.
//!
//! W
    
    pub fn set_affinity(&mut self, new_affinity: CpuSet) -> Result<()> {
        if new_affinity.empty() {
            return_errno!(EINVAL, "there must be at least one CPU core in the CpuSet");
        }
        if !new_affinity.is_subset_of(&AVAIL_CPUSET) {
            return_errno!(
                EINVAL,
                "one or some of the CPU cores are not available to set"
            );
        }
        match self.inner_mut() {
            Inner::Detached { affinity } => {
                *affinity.as_mut() = new_affinity;
            }
            Inner::Attached { host_tid, affinity } => {
                update_affinity(*host_tid, &new_affinity);
                *affinity = new_affinity;
            }
        };
        Ok(())
    }