Skip to content

Commit

Permalink
Generate Rust wrappers for class structs too
Browse files Browse the repository at this point in the history
  • Loading branch information
sdroege committed Nov 10, 2017
1 parent 0409d73 commit afe29c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/analysis/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use traits::*;
pub struct Info {
pub base: InfoBase,
pub c_type: String,
pub class_type: Option<String>,
pub c_class_type: Option<String>,
pub get_type: String,
pub supertypes: Vec<general::StatusedTypeId>,
Expand Down Expand Up @@ -218,6 +219,7 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
let info = Info {
base: base,
c_type: klass.c_type.clone(),
class_type: klass.type_struct.clone(),
c_class_type: klass.c_class_type.clone(),
get_type: klass.glib_get_type.clone(),
supertypes: supertypes,
Expand Down Expand Up @@ -341,6 +343,7 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I
let info = Info {
base: base,
c_type: iface.c_type.clone(),
class_type: iface.type_struct.clone(),
c_class_type: iface.c_class_type.clone(),
get_type: iface.glib_get_type.clone(),
supertypes: supertypes,
Expand Down
5 changes: 3 additions & 2 deletions src/codegen/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn define_object_type(
env: &Env,
type_name: &str,
glib_name: &str,
class_name: &Option<&str>,
glib_class_name: &Option<&str>,
glib_func_name: &str,
parents: &[StatusedTypeId],
Expand All @@ -64,8 +65,8 @@ pub fn define_object_type(
.collect();

let (separator, class_name) = {
if let &Some(s) = glib_class_name {
(", ".to_string(), format!("ffi::{}", s))
if let (&Some(name), &Some(ffi_name)) = (class_name, glib_class_name) {
(", ".to_string(), format!("{}, ffi::{}", name, ffi_name))
} else {
("".to_string(), "".to_string())
}
Expand Down
1 change: 1 addition & 0 deletions src/codegen/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn generate(w: &mut Write, env: &Env, analysis: &analysis::object::Info) ->
env,
&analysis.name,
&analysis.c_type,
&analysis.class_type.as_ref().map(|s| &s[..]),
&analysis.c_class_type.as_ref().map(|s| &s[..]),
&analysis.get_type,
&analysis.supertypes,
Expand Down

0 comments on commit afe29c2

Please sign in to comment.