diff options
author | Jesse Luehrs <doy@tozt.net> | 2016-04-27 01:50:04 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2016-04-27 01:50:36 -0400 |
commit | 85213a843566b82b05626efd97c48644b04935d2 (patch) | |
tree | 1897cb51bd0519aa955310ca049a09064e9a476d /src/cell.rs | |
parent | f0486657754c485f8211c6d00f9bf5ba6953dd67 (diff) | |
download | vt100-rust-85213a843566b82b05626efd97c48644b04935d2.tar.gz vt100-rust-85213a843566b82b05626efd97c48644b04935d2.zip |
start implementing cells
Diffstat (limited to 'src/cell.rs')
-rw-r--r-- | src/cell.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/cell.rs b/src/cell.rs new file mode 100644 index 0000000..7590e98 --- /dev/null +++ b/src/cell.rs @@ -0,0 +1,30 @@ +use libc; +use std; + +use types; + +pub struct Cell(*mut types::CellImpl); + +#[repr(C)] +struct CellPrefix { + pub contents: [libc::c_char; 8], + pub len: libc::size_t, +} + +impl Cell { + pub fn new(cell_impl: *mut types::CellImpl) -> Cell { + Cell(cell_impl) + } + + pub fn contents(&self) -> &str { + let Cell(cell_impl) = *self; + let contents: &[u8] = unsafe { + let prefix: *mut CellPrefix = std::mem::transmute(cell_impl); + std::slice::from_raw_parts( + &(*prefix).contents as *const i8 as *const u8, + (*prefix).len + ) + }; + std::str::from_utf8(contents).unwrap() + } +} |