pub struct Plain<T>(pub T);
Expand description

Used to write values as they are represented in memory.

Examples

Writing struct into a sink.

use write_into::{Plain, write_into};
 
struct Rgba {
    r: u8,
    g: u8,
    b: u8,
    a: u8,
}
 
let color = Rgba { r: 0x18, g: 0x18, b: 0x18, a: 0xFF };
let mut buffer = Vec::new();
write_into(&mut buffer, Plain(&color)).unwrap();
assert_eq!(&buffer, &[0x18, 0x18, 0x18, 0xFF]);

Writing array into a sink.

use write_into::{Plain, write_into};
 
let bytes: &[u8; 4] = b"\0asm";
let mut buffer = Vec::new();
write_into(&mut buffer, Plain(bytes)).unwrap();
assert_eq!(&buffer, b"\0asm");

Writing slice into a sink (the crate also provide implementation for Plain<&str>).

use write_into::{Plain, write_into};
 
let bytes: &[u8] = b"([java/lang/String;)V";
let mut buffer = Vec::new();
write_into(&mut buffer, Plain(bytes)).unwrap();
assert_eq!(&buffer, b"([java/lang/String;)V");

Tuple Fields

0: T

Trait Implementations

Transmutes arbitrary value into a byte slice.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Transmutes arbitrary slice into a byte slice.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Result of WriteInto::write_into function (e.g. () or usize).

Writes value into I/O sink.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.