Struct doors::Client

source ·
pub struct Client(_);
Expand description

Less unsafe door client (compared to raw file descriptors)

Clients are automatically closed when they go out of scope. Errors detected on closing are ignored by the implementation of Drop, just like in File.

Implementations§

source§

impl Client

source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open a door client like you would a file

source

pub fn call(&self, arg: DoorArgument) -> Result<DoorArgument, DoorCallError>

Issue a door call

You are responsible for managing this memory. See DOOR_CALL(3C). Particularly, if, after a door_call, the rbuf property of door_arg_t is different than what it was before the door_call, you are responsible for reclaiming this area with MUNMAP(2) when you are done with it.

This crate cannot yet handle this for you. See Issue #11.

source

pub fn call_with_data(&self, data: &[u8]) -> Result<DoorArgument, DoorCallError>

Issue a door call with Data only

Example
use doors::Client;
use std::ffi::CString;
use std::ffi::CStr;

let capitalize = Client::open("/tmp/barebones_capitalize.door")
    .unwrap();
let text = CString::new("Hello, World!").unwrap();
let response = capitalize.call_with_data(text.as_bytes()).unwrap();
let caps = unsafe {
    CStr::from_ptr(response.data().as_ptr() as *const i8)
};
assert_eq!(caps.to_str(), Ok("HELLO, WORLD!"));

Trait Implementations§

source§

impl Drop for Client

source§

fn drop(&mut self)

Automatically close the door on your way out.

This will close the file descriptor associated with this door, so that this process will no longer be able to call this door. For that reason, it is a programming error to Clone this type.

source§

impl FromRawFd for Client

source§

unsafe fn from_raw_fd(raw: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.