From f822099d40d47d3535396bf533d346b40df2a369 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 17 Sep 2015 23:03:41 -0500 Subject: [PATCH] Implement "Srv" struct. --- src/lib.rs | 3 +++ src/raw/srv.rs | 4 ++-- src/srv.rs | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8311552..7ad27ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,9 @@ pub mod srv; pub mod gfx; pub mod services; +pub use srv::Srv; +pub use gfx::Gfx; + #[lang = "stack_exhausted"] extern fn stack_exhausted() {} #[lang = "eh_personality"] extern fn eh_personality() {} #[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } diff --git a/src/raw/srv.rs b/src/raw/srv.rs index f06a1b4..c327973 100644 --- a/src/raw/srv.rs +++ b/src/raw/srv.rs @@ -1,5 +1,5 @@ -use super::*; -use super::super::{Result, Handle}; +use ::raw::*; +use ::{Result, Handle}; extern "C" { pub fn srvInit() -> Result; diff --git a/src/srv.rs b/src/srv.rs index 44fb956..3999458 100644 --- a/src/srv.rs +++ b/src/srv.rs @@ -1,13 +1,26 @@ -use ::Result; -use ::raw::srv; +use ::raw::srv::*; -pub fn init() -> Result { - unsafe { - return srv::srvInit(); +use core::marker::PhantomData; + +pub struct Srv { + pd: PhantomData +} + +impl Srv { + pub fn new() -> Result { + unsafe { + let r = srvInit(); + if r < 0 { + Err(r) + } else { + Ok(Srv { pd: PhantomData }) + } + } } } -pub fn exit() -> Result { - unsafe { - return srv::srvExit(); + +impl Drop for Srv { + fn drop(&mut self) { + unsafe { srvExit() }; } }