cluproccmdline

Crates.iocluproccmdline
lib.rscluproccmdline
version0.1.5
sourcesrc
created_at2018-05-06 13:40:40.558744
updated_at2018-07-28 13:07:44.149643
descriptionFast secure parsing /proc/cmdline.
homepage
repositoryhttps://github.com/clucompany/cluProcCmdline.git
max_upload_size
id63987
size33,589
Denis Kotlyarov (denisandroid)

documentation

README

cluProcCmdline

Build Status Apache licensed crates.io Documentation

Fast secure parsing /proc/cmdline.

Use DefaultIter:

1

use cluproccmdline::Cmdline;

let mut cmdline = cluproccmdline::this_machine().unwrap();
for (name, value) in cmdline.iter() {
		if let Some(name) = name {
				println!(
						"Cmdline_str: {} {}", 
						String::from_utf8(name.to_vec()).unwrap(), 
						String::from_utf8(value.to_vec()).unwrap()
				);
		}
		// OUTPUT: 
		// IF /proc/cmdline = "BOOT_IMAGE=/boot/vmlinuz-linux-zen nmi_watchdog=0"
		// TO -> "Cmdline_str: BOOT_IMAGE /boot/vmlinuz-linux-zen"
		// TO -> "Cmdline_str: nmi_watchdog 0"
}	

2

use cluproccmdline::Cmdline;

let mut cmdline = cluproccmdline::array_slice(b"test=all rw");
let mut iter = cmdline.iter();

while let Some((Some(name), value)) = iter.next() {
		println!("{} {}", 
				String::from_utf8(name.to_vec()).unwrap(), 
				String::from_utf8(value.to_vec()).unwrap()
		);
		// OUTPUT:
		// rw
}

Use OneIter:

1

use cluproccmdline::Cmdline;

let mut cmdline = cluproccmdline::array_slice(b"test=all rw");
for value in cmdline.iter_one() {
		println!("{}", 
				String::from_utf8(value.to_vec()).unwrap()
		);
		// OUTPUT: 
		// rw
}

2

use cluproccmdline::Cmdline;

let mut cmdline = cluproccmdline::array_slice(b"test=all rw");
let mut iter = cmdline.iter_one();

while let Some(value) = iter.next() {
		println!("{}", 
				String::from_utf8(value.to_vec()).unwrap()
		);
		// OUTPUT:
		// rw
}

Use TwoIter:

use cluproccmdline::Cmdline;

let mut cmdline = cluproccmdline::array_slice(b"test=all rw");
for (value, name) in cmdline.iter_two() {
		println!("{} {}", 
				String::from_utf8(name.to_vec()).unwrap(),
				String::from_utf8(value.to_vec()).unwrap()
		);
		// OUTPUT: 
		// test all
}

Hash proc cmdline

use cluproccmdline::Cmdline;

let mut cmdline = cluproccmdline::array_slice(b"test=all rw");
assert_eq!(cmdline.cmdline_hash(), 1877887864476248772);

Benchmark

Machine: Intel Core 2 Duo (2000 MHz), 2 Gb DDR2

test tests::bench_oneslice_new ... bench:         101 ns/iter (+/- 14)
test tests::bench_slice_new    ... bench:         105 ns/iter (+/- 23)

License

Copyright 2018 #UlinProject Денис Котляров

Licensed under the Apache License, Version 2.0

Commit count: 27

cargo fmt