Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Overhaul for Rust 0.12 #14

Merged
merged 12 commits into from
Oct 1, 2014
Merged

Overhaul for Rust 0.12 #14

merged 12 commits into from
Oct 1, 2014

Conversation

mzabaluev
Copy link
Member

Resolves #12, #7, #4, #10.

As of GLib 2.36, it's not necessary to call g_type_init().
This was the only reason for a global init function.
Update to the Rust syntax as of
rustc 0.12.0-nightly (740905042 2014-09-29).

Rearranged the API conventions:
* The imported structure types are now represented as the C structures
  themselves and declared in the crate root.
* The interface traits live in the interface:: submodule. They still have
  the same name as their instance structure, but I consider the little
  disambiguation boilerplate on usage as better than having to deal with
  name mangling issues. There are some other submodules for other utility
  stuff such as callback shims.
* Upcasting is implemented in interface traits, as well as a way to get
  at the instance structure by reference (cumbersome as it is pending
  the trait reform and UFCS). The dynamic casting continues to be available
  for types implementing ObjectType.
* A generic reference type refcount::Ref provides safe reference counting,
  and is made non-sendable and non-sync.
With this, we need just the raw function table from Refcount,
no need for the default-impl methods. Also, the generic impl
of Ref got slim.
This reference type is for sendable, synchronized wrappers
of GLib objects such as GMainLoop and GMainContext.

There is a need to pass these objects into sendable closures, for example
to quit the mainloop, or to send callback closures to another task's
mainloop.
Want to be explicit as to the costs at the call site.
Added a RAII wrapper LoopRunner around creating a GMainContext,
pushing it as the thread default, and creating a GMainLoop to run it.
The MainLoop wrapper can be reffed out for closures and such.

While Rust RFC 0062 (removal of non-native runtimes) hasn't landed,
MainLoop and LoopRunner are kept in the module native as a
reminder that they are only safe to use with the native runtime.
The idea is to ensure that the API user can only access the
MainLoop and the MainContext after those have been properly set up,
and also they can be sure to invoke async closures in the thread-default
context of the loop as long as they do it in the closure.

With the thread context setup done implicitly when calling
LoopRunner::new(), it was possible to get confusing behavior by
inadvertently swapping creation of the runner and issuing async operations.

The users can still get their callbacks to never be called by
invoking async methods outside run_after, but it's not a program safety
issue, and it should be familiar to any Gio programmer.
Implemented an into_string() method and Equiv for Str.
Changed the bogus signature and implementation of gio::File::get_path
to one returning a gstr::Utf8.
Test all the limited ways we can now get at the string data.
mzabaluev added a commit that referenced this pull request Oct 1, 2014
@mzabaluev mzabaluev merged commit 62b27ec into master Oct 1, 2014
@mzabaluev mzabaluev deleted the rust-0.12 branch October 1, 2014 06:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update for Rust 0.12-pre
1 participant