Struct Matrix

Source
pub struct Matrix { /* private fields */ }

Implementations§

Source§

impl Matrix

Hexadecimal matrix structure

§Examples

let arr = "".as_bytes();
let mut m = Matrix::new(20, arr.to_vec());
Source

pub fn new(w: usize, b: Vec<u8>) -> Self

Examples found in repository?
examples/main.rs (line 19)
13fn main() {
14    // serialized string
15    println!("-------------------------------- serialized string --------------------------------");
16    let arr = "JOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJEORIJOQWEJREOI
17    QIWJEORIJOQWEJREOIQIJOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJEORIJOQWEJREOI
18    QIWJEORIJOQWEJREOIQIWJEORIJvQIWJQIWJEORIJOQWEJREOIQIWJEORIJvvOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJE ".as_bytes();
19    let mut m = Matrix::new(20, arr.to_vec());
20    m.print_matrix();
21    // serialized struct
22    println!("-------------------------------- serialized struct --------------------------------");
23    let t = Test {
24        a: 1,
25        b: String::from("test"),
26    };
27    let encoded: Vec<u8> = serialize(&t).unwrap();
28    let mut m = Matrix::new(20, encoded.to_vec());
29    m.print_matrix();
30    // serialized file
31    println!("-------------------------------- serialized file --------------------------------");
32    let buffer = fs::read("/resource/TEST_1").expect("read file error");
33    let mut m = Matrix::new(20, buffer.to_vec());
34    m.print_matrix();
35    println!(
36        "-------------------------------- line by line processing --------------------------------"
37    );
38    let lines = m.lines();
39    for (i, v) in lines.iter().enumerate() {
40        println!(
41            "line no:{}, line hex:{}, line info:{}",
42            v.no(),
43            v.hex(),
44            v.info()
45        );
46    }
47}
Source

pub fn print_matrix(&mut self)

print matrix

§Examples
let arr = "".as_bytes();
let mut m = Matrix::new(20, arr.to_vec());
m.print_matrix();
Examples found in repository?
examples/main.rs (line 20)
13fn main() {
14    // serialized string
15    println!("-------------------------------- serialized string --------------------------------");
16    let arr = "JOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJEORIJOQWEJREOI
17    QIWJEORIJOQWEJREOIQIJOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJEORIJOQWEJREOI
18    QIWJEORIJOQWEJREOIQIWJEORIJvQIWJQIWJEORIJOQWEJREOIQIWJEORIJvvOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJE ".as_bytes();
19    let mut m = Matrix::new(20, arr.to_vec());
20    m.print_matrix();
21    // serialized struct
22    println!("-------------------------------- serialized struct --------------------------------");
23    let t = Test {
24        a: 1,
25        b: String::from("test"),
26    };
27    let encoded: Vec<u8> = serialize(&t).unwrap();
28    let mut m = Matrix::new(20, encoded.to_vec());
29    m.print_matrix();
30    // serialized file
31    println!("-------------------------------- serialized file --------------------------------");
32    let buffer = fs::read("/resource/TEST_1").expect("read file error");
33    let mut m = Matrix::new(20, buffer.to_vec());
34    m.print_matrix();
35    println!(
36        "-------------------------------- line by line processing --------------------------------"
37    );
38    let lines = m.lines();
39    for (i, v) in lines.iter().enumerate() {
40        println!(
41            "line no:{}, line hex:{}, line info:{}",
42            v.no(),
43            v.hex(),
44            v.info()
45        );
46    }
47}
Source

pub fn reset(&mut self, b: &[u8])

reset matrix

§Examples
let arr = "".as_bytes();
let mut m = Matrix::new(20, arr.to_vec());

let arr2 = "".as_bytes();
m.reset(arr2);
Source

pub fn get_line_by_index(&mut self, index: usize) -> &mut Line

reset matrix

§Examples
let arr = "".as_bytes();
let mut m = Matrix::new(20, arr.to_vec());

let line = m.get_line_by_index(index);
Source

pub fn line_count(&self) -> usize

reset matrix

§Examples
let arr = "".as_bytes();
let mut m = Matrix::new(20, arr.to_vec());

println("{}", m.line_count());
Source

pub fn lines(&self) -> Vec<Line>

get matrix line

§Examples
let arr = "".as_bytes();
let mut m = Matrix::new(20, arr.to_vec());

let lines : Vec<Line> = m.lines();
for (i,v) in lines.iter().enumerate()
{
  // ....
}
Examples found in repository?
examples/main.rs (line 38)
13fn main() {
14    // serialized string
15    println!("-------------------------------- serialized string --------------------------------");
16    let arr = "JOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJEORIJOQWEJREOI
17    QIWJEORIJOQWEJREOIQIJOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJEORIJOQWEJREOI
18    QIWJEORIJOQWEJREOIQIWJEORIJvQIWJQIWJEORIJOQWEJREOIQIWJEORIJvvOQWEJREOJOQWEJREOIQIWJEORIJOQWEJREOIQIWJE ".as_bytes();
19    let mut m = Matrix::new(20, arr.to_vec());
20    m.print_matrix();
21    // serialized struct
22    println!("-------------------------------- serialized struct --------------------------------");
23    let t = Test {
24        a: 1,
25        b: String::from("test"),
26    };
27    let encoded: Vec<u8> = serialize(&t).unwrap();
28    let mut m = Matrix::new(20, encoded.to_vec());
29    m.print_matrix();
30    // serialized file
31    println!("-------------------------------- serialized file --------------------------------");
32    let buffer = fs::read("/resource/TEST_1").expect("read file error");
33    let mut m = Matrix::new(20, buffer.to_vec());
34    m.print_matrix();
35    println!(
36        "-------------------------------- line by line processing --------------------------------"
37    );
38    let lines = m.lines();
39    for (i, v) in lines.iter().enumerate() {
40        println!(
41            "line no:{}, line hex:{}, line info:{}",
42            v.no(),
43            v.hex(),
44            v.info()
45        );
46    }
47}

Auto Trait Implementations§

§

impl Freeze for Matrix

§

impl RefUnwindSafe for Matrix

§

impl Send for Matrix

§

impl Sync for Matrix

§

impl Unpin for Matrix

§

impl UnwindSafe for Matrix

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.