Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

The kmod context

let ctx = kmod::Context::new().unwrap();

Implementations§

Source§

impl Context

Source

pub fn new() -> Result<Context>

Create a new kmod context.

let ctx = kmod::Context::new().unwrap();
Source

pub fn new_with_dirname(dirname: &Path) -> Result<Context>

Create a new kmod context with given directory to search for kernel modules.

use std::path::Path;
let ctx = kmod::Context::new_with_dirname(&Path::new("/lib/modules/6.0.9")).unwrap();
Source

pub fn modules_loaded(&self) -> Result<ModuleIterator>

Get an iterator of all loaded modules.

let ctx = kmod::Context::new().unwrap();
for module in ctx.modules_loaded().unwrap() {
    // ...
}
Source

pub fn module_new_from_lookup<S: AsRef<OsStr>>( &self, alias: S, ) -> Result<ModuleIterator>

Create a module struct by looking up a name or alias.

use std::ffi::{OsStr, OsString};
let ctx = kmod::Context::new()?;
let module = ctx.module_new_from_lookup(&OsString::from("vfat"))?;
Source

pub fn module_new_from_path<S: AsRef<OsStr>>( &self, filename: S, ) -> Result<Module>

Create a module struct by path.

let ctx = kmod::Context::new().unwrap();
let module = ctx.module_new_from_path("foo.ko");
Source

pub fn module_new_from_name(&self, name: &str) -> Result<Module>

Create a module struct by name.

let ctx = kmod::Context::new().unwrap();
let module = ctx.module_new_from_name("tun").unwrap();
Source

pub fn dirname(&self) -> OsString

Get the directory where kernel modules are stored

let ctx = kmod::Context::new().unwrap();
let dirname = ctx.dirname();

Trait Implementations§

Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.