Commit 740d6e8a authored by John Hodge's avatar John Hodge

Updated documentation and restructure to centralise docs

parent 6dd0deaf
[package] [package]
name = "va_list" name = "va_list"
version = "0.0.2" version = "0.0.3"
authors = [ "John Hodge <tpg@mutabah.net>" ] authors = [ "John Hodge <tpg@mutabah.net>" ]
description = "Provides a rust implementation of the 'va_list' type for a small set of ABIs. Allowing rust implementations of functions like vprintf." description = "Provides a rust implementation of the 'va_list' type for a small set of ABIs. Allowing rust implementations of functions like vprintf."
repository = "https://github.com/thepowersgang/va_list-rs" repository = "https://github.com/thepowersgang/va_list-rs"
......
/* /*
* *
*/ */
#[cfg(nightly)] use core::{mem,ptr}; use std::{mem,ptr};
#[cfg(not(nightly))] use std::{mem,ptr};
use super::VaPrimitive; use super::VaPrimitive;
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
......
// x86_64 ELF - Aka the Itanium ABI
//
use std::{mem,ptr}; use std::{mem,ptr};
use super::VaPrimitive; use super::VaPrimitive;
#[allow(non_camel_case_types)]
/// Core type as passed though the FFI
pub struct VaList(*mut VaListInner); pub struct VaList(*mut VaListInner);
// /// Saves the state of the VaList, similar to va_copy // /// Saves the state of the VaList, similar to va_copy
//impl Clone for VaList { fn clone(&self) -> Self { va_list(self.0) } } //impl Clone for VaList { fn clone(&self) -> Self { va_list(self.0) } }
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
#[allow(raw_pointer_derive)]
#[doc(hidden)] #[doc(hidden)]
pub struct VaListInner pub struct VaListInner
{ {
...@@ -22,14 +20,6 @@ pub struct VaListInner ...@@ -22,14 +20,6 @@ pub struct VaListInner
impl VaList impl VaList
{ {
/// Read a value from the VaList
///
/// Users should take care that they are reading the correct type
pub unsafe fn get<T: VaPrimitive>(&mut self) -> T {
//log_debug!("inner = {:p} {:?}", self.0, *self.0);
T::get(self)
}
fn inner(&mut self) -> &mut VaListInner { fn inner(&mut self) -> &mut VaListInner {
// This pointer should be valid // This pointer should be valid
unsafe { &mut *self.0 } unsafe { &mut *self.0 }
......
...@@ -4,9 +4,25 @@ ...@@ -4,9 +4,25 @@
* This crate provides an interface for rust code to read values passed in C's va_list type. * This crate provides an interface for rust code to read values passed in C's va_list type.
* *
* ## Example * ## Example
* In C Code
* ```c
* #include <stdint.h>
* #include <stdarg.h>
* extern void print_ints_va(uint32_t count, va_list args);
* extern void print_ints(uint32_t count, ...)
* {
* va_list args;
* va_start(args, count);
* print_ints_va(count, args);
* va_end(args);
* }
* ```
*
* In rust code:
* ```rust * ```rust
* extern crate va_list; * extern crate va_list;
* *
* #[no_mangle]
* extern "C" fn print_ints_va(count: u32, mut args: va_list::VaList) * extern "C" fn print_ints_va(count: u32, mut args: va_list::VaList)
* { * {
* unsafe { * unsafe {
...@@ -17,35 +33,50 @@ ...@@ -17,35 +33,50 @@
* } * }
* ``` * ```
*/ */
#![cfg_attr(any(feature="no_std",nightly),feature(no_std))] #![cfg_attr(feature="no_std",no_std)]
#![cfg_attr(any(feature="no_std",no_std),no_std)]
#![crate_type="lib"] #![crate_type="lib"]
#![crate_name="va_list"] #![crate_name="va_list"]
#[cfg(any(feature="no_std",no_std))] #[doc(hidden)] #[cfg(feature="no_std")]
#[doc(hidden)]
mod std { mod std {
pub use core::{mem,ptr}; pub use core::{mem,ptr};
} }
// x86_64 on unix platforms is _usually_ ELF. // x86_64 on unix platforms is _usually_ ELF.
#[cfg(target_arch="x86_64")] #[cfg(target_family="unix")] #[cfg(all( target_arch="x86_64", target_family="unix" ))]
#[path="impl-x86_64-elf.rs"] mod imp; #[path="impl-x86_64-elf.rs"] mod imp;
//// x86_64 on windows is special //// x86_64 on windows is special
//#[cfg(target_arch="x86_64")] #[cfg(target_family="windows")] //#[cfg(all( target_arch="x86_64", target_family="windows" ))]
//#[path="impl-x86_64-elf.rs"] mod imp; //#[path="impl-x86_64-elf.rs"] mod imp;
// x86+unix = cdecl // x86+unix = cdecl
#[cfg(target_arch="x86")] #[cfg(target_family="unix")] #[cfg(all( target_arch="x86", target_family="unix" ))]
#[path="impl-x86-sysv.rs"] mod imp; #[path="impl-x86-sysv.rs"] mod imp;
#[cfg(target_arch="arm")] #[cfg(target_family="unix")] // arm+unix = cdecl
#[cfg(all( target_arch="arm", target_family="unix" ))]
#[path="impl-arm-sysv.rs"] mod imp; #[path="impl-arm-sysv.rs"] mod imp;
pub use imp::VaList; /// Rust version of C's `va_list` type from the `stdarg.h` header
pub struct VaList(imp::VaList);
/// Core type as passed though the FFI
impl VaList
{
/// Read a value from the VaList.
///
/// Users should take care that they are reading the correct type
pub unsafe fn get<T: VaPrimitive>(&mut self) -> T {
T::get(&mut self.0)
}
}
/// Trait implemented on types that can be read from a va_list /// Trait implemented on types that can be read from a va_list
pub trait VaPrimitive: 'static pub trait VaPrimitive: 'static
{ {
#[doc(hidden)] #[doc(hidden)]
unsafe fn get(&mut VaList) -> Self; unsafe fn get(&mut imp::VaList) -> Self;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment