New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Object::new() around g_object_newv() for instantiating obje… #302

Merged
merged 1 commit into from Mar 29, 2018

Conversation

Projects
None yet
3 participants
@sdroege
Member

sdroege commented Mar 27, 2018

…cts by type id

@GuillaumeGomez

This comment has been minimized.

Show comment
Hide comment
@GuillaumeGomez

GuillaumeGomez Mar 27, 2018

Member

Seems good to me!

Member

GuillaumeGomez commented Mar 27, 2018

Seems good to me!

use std::ffi::CString;
if !type_.is_a(&Object::static_type()) {
return Err(BoolError("Can't instantiate non-GObject objects"));

This comment has been minimized.

@sdroege

sdroege Mar 27, 2018

Member

In theory this could be an assertion, it's a definite programming error

@sdroege

sdroege Mar 27, 2018

Member

In theory this could be an assertion, it's a definite programming error

let params = properties.iter()
.map(|&(name, value)|
(CString::new(name).unwrap(), value.to_value()))
.collect::<Vec<_>>();

This comment has been minimized.

@sdroege

sdroege Mar 27, 2018

Member

We could also check for all properties if they actually exist and are of the given value, and assert otherwise or return an error.

@sdroege

sdroege Mar 27, 2018

Member

We could also check for all properties if they actually exist and are of the given value, and assert otherwise or return an error.

if ptr.is_null() {
Err(BoolError("Can't instantiate object"))
} else {
if type_.is_a(&from_glib(gobject_ffi::g_initially_unowned_get_type())) {

This comment has been minimized.

@EPashkin

EPashkin Mar 27, 2018

Member

Maybe better } else if ..

@EPashkin

EPashkin Mar 27, 2018

Member

Maybe better } else if ..

This comment has been minimized.

@sdroege

sdroege Mar 27, 2018

Member

Why? That whole branch is the non-NULL case :)

@sdroege

sdroege Mar 27, 2018

Member

Why? That whole branch is the non-NULL case :)

This comment has been minimized.

@EPashkin

EPashkin Mar 27, 2018

Member

For me it looks as tree-way choice, and all 3 cases is equivalent

@EPashkin

EPashkin Mar 27, 2018

Member

For me it looks as tree-way choice, and all 3 cases is equivalent

@EPashkin

This comment has been minimized.

Show comment
Hide comment
@EPashkin

EPashkin Mar 27, 2018

Member

@sdroege Thanks, +1
Only small nit, that can be ignored.

Member

EPashkin commented Mar 27, 2018

@sdroege Thanks, +1
Only small nit, that can be ignored.

@sdroege

This comment has been minimized.

Show comment
Hide comment
@sdroege

sdroege Mar 29, 2018

Member

Ok, let's get it in then?

Member

sdroege commented Mar 29, 2018

Ok, let's get it in then?

@GuillaumeGomez

This comment has been minimized.

Show comment
Hide comment
@GuillaumeGomez

GuillaumeGomez Mar 29, 2018

Member

Let's go then!

Member

GuillaumeGomez commented Mar 29, 2018

Let's go then!

@GuillaumeGomez GuillaumeGomez merged commit 9c84398 into gtk-rs:master Mar 29, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment