Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Overhaul GValue bindings #95

Merged
merged 9 commits into from
Jan 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub use self::object::{
pub use self::permission::Permission;
pub use self::source::{Continue, idle_add, timeout_add, timeout_add_seconds};
pub use self::traits::FFIGObject;
pub use self::value::{Value, ValuePublic};
pub use types::Type;
pub use value::{TypedValue, Value};
pub use self::date::{TimeVal, Time, Date, Year, Month, Weekday, Day};

#[macro_use]
Expand All @@ -79,7 +79,7 @@ pub mod signal;
pub mod source;
pub mod traits;
pub mod translate;
mod value;
pub mod value;

pub mod types;
pub mod date;
Expand Down
44 changes: 36 additions & 8 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub enum Type {
I32,
/// The fundamental type corresponding to `u32`
U32,
/// The fundamental type corresponding to `isize`
ISize,
/// The fundamental type corresponding to `usize`
USize,
/// The fundamental type corresponding to C `long`
ILong,
/// The fundamental type corresponding to C `unsigned long`
ULong,
/// The fundamental type corresponding to `i64`
I64,
/// The fundamental type corresponding to `u64`
Expand Down Expand Up @@ -61,6 +61,34 @@ pub trait StaticType {
fn static_type() -> Type;
}

impl<'a, T: ?Sized + StaticType> StaticType for &'a T {
fn static_type() -> Type {
T::static_type()
}
}

macro_rules! builtin {
($name:ident, $val:ident) => {
impl StaticType for $name {
fn static_type() -> Type {
Type::$val
}
}
}
}

builtin!(bool, Bool);
builtin!(i8, I8);
builtin!(u8, U8);
builtin!(i32, I32);
builtin!(u32, U32);
builtin!(i64, I64);
builtin!(u64, U64);
builtin!(f32, F32);
builtin!(f64, F64);
builtin!(str, String);
builtin!(String, String);

pub trait InstanceType {
fn instance_type(&self) -> Type;
}
Expand All @@ -87,8 +115,8 @@ impl FromGlib<glib_ffi::GType> for Type {
gobject_ffi::G_TYPE_BOOLEAN => Bool,
gobject_ffi::G_TYPE_INT => I32,
gobject_ffi::G_TYPE_UINT => U32,
gobject_ffi::G_TYPE_LONG => ISize,
gobject_ffi::G_TYPE_ULONG => USize,
gobject_ffi::G_TYPE_LONG => ILong,
gobject_ffi::G_TYPE_ULONG => ULong,
gobject_ffi::G_TYPE_INT64 => I64,
gobject_ffi::G_TYPE_UINT64 => U64,
gobject_ffi::G_TYPE_ENUM => BaseEnum,
Expand Down Expand Up @@ -120,8 +148,8 @@ impl ToGlib for Type {
Bool => gobject_ffi::G_TYPE_BOOLEAN,
I32 => gobject_ffi::G_TYPE_INT,
U32 => gobject_ffi::G_TYPE_UINT,
ISize => gobject_ffi::G_TYPE_LONG,
USize => gobject_ffi::G_TYPE_ULONG,
ILong => gobject_ffi::G_TYPE_LONG,
ULong => gobject_ffi::G_TYPE_ULONG,
I64 => gobject_ffi::G_TYPE_INT64,
U64 => gobject_ffi::G_TYPE_UINT64,
BaseEnum => gobject_ffi::G_TYPE_ENUM,
Expand Down
Loading