Commit Graph

354 Commits

Author SHA1 Message Date
Linus Färnstrand 4e9cbd7387 Add test for as_untyped 2017-11-28 16:46:33 +01:00
Linus Färnstrand 31fcb64bf1 Fix bug in CFArray::to_untyped that made the retain count wrong 2017-11-28 16:19:31 +01:00
bors-servo 1a49dbb55c Auto merge of #136 - faern:boolean-from-bool, r=jdm
Add conversion to and from bool for CFBoolean

Make it possible to convert back and fourth between Rust booleans and `CFBoolean`

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/136)
<!-- Reviewable:end -->
2017-11-27 09:38:03 -06:00
Linus Färnstrand f0766c35c2 Add conversion to and from bool for CFBoolean 2017-11-27 16:18:40 +01:00
bors-servo 94d48c20b1 Auto merge of #137 - faern:impl-from-for-cfnumber, r=jdm
Implement From<_> for CFNumber

All the `from_` methods on `CFNumber` can be expressed with implementing the `From` trait and thus enable it to be used a bit more ergonomic in some cases. And feels more idiomatic IMO.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/137)
<!-- Reviewable:end -->
2017-11-27 08:51:43 -06:00
Linus Färnstrand 3ef9e779b0 Implement From<_> for CFNumber 2017-11-27 15:10:40 +01:00
bors-servo 490d24a639 Auto merge of #138 - nox:bump, r=nox
Bump core-foundation-sys version to 0.4.5

This is needed to publish a new core-foundation-rs version.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/138)
<!-- Reviewable:end -->
2017-11-27 07:31:44 -06:00
Anthony Ramine cc66c00ac3 Bump core-foundation-sys version to 0.4.5
This is needed to publish a new core-foundation-rs version.
2017-11-27 14:30:18 +01:00
bors-servo 654a7fdbc1 Auto merge of #133 - jrmuizel:bump-version, r=nox
Bump version for CFArray changes

This is needed for https://github.com/servo/core-graphics-rs/pull/104

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/133)
<!-- Reviewable:end -->
2017-11-27 07:05:50 -06:00
bors-servo 4a9328efcb Auto merge of #134 - jrmuizel:unsafe, r=nox
Mark FromVoid more appropriately as unsafe

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/134)
<!-- Reviewable:end -->
2017-11-27 06:43:42 -06:00
Jeff Muizelaar 8514c48110 Mark FromVoid more appropriately as unsafe 2017-11-26 19:00:44 -05:00
Jeff Muizelaar eb4e452d56 Bump version for CFArray changes 2017-11-26 17:55:51 -05:00
bors-servo f9e854536e Auto merge of #127 - jrmuizel:cfarray-type, r=jdm
Add a type parameter to CFArray

This puts us on a path to greater type safety when using CFArrays

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/127)
<!-- Reviewable:end -->
2017-11-25 14:41:42 -06:00
Jeff Muizelaar 0253ee24ba Add a type parameter to CFArray
This puts us on a path to greater type safety when using CFArrays
2017-11-25 13:02:04 -05:00
bors-servo 063ba16ace Auto merge of #131 - faern:implement-propertylist, r=jdm
Add CFPropertyList and methods for casting to subclasses

https://developer.apple.com/documentation/corefoundation/cfpropertylist-rif specifies the following types as valid subclasess of a property list:
CFData, CFString, CFArray, CFDictionary, CFDate, CFBoolean, and CFNumber.

So I add a trait, `CFPropertyListSubClass`, and implement it for the valid types. Then add the `CFPropertyList` type and make it work as much as possible as the other `TCFType`s. However, it can't implement that trait, since it can't implement the static method `type_id`.

The main point of adding this was to then get to the convenience methods `to_CFPropertyList` and `downcast` that allows safe casting between the subclasses and the superclass. This is handy in calls such as `SCDynamicStoreSetValue` and `SCDynamicStoreCopyValue` where the methods either accept or return a `CFPropertyListRef`. With this addition it becomes easy to write safe wrappers around those functions and make them accept proper, constrained types.

Disclaimer: I'm not yet super familiar with CF. So I can only hope this is safe and sound, but I think it is.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/131)
<!-- Reviewable:end -->
2017-11-24 10:22:57 -06:00
Linus Färnstrand cc1197c371 Change downcast to return Option<T> 2017-11-24 16:30:03 +01:00
Linus Färnstrand 343b0c9a9a Improve documentation with links 2017-11-24 15:48:28 +01:00
Linus Färnstrand 2b7d15941e Add proper error for CFPropertyList::downcast 2017-11-24 15:31:24 +01:00
Linus Färnstrand ac6cc9f5d9 Add CFPropertyList and methods for casting to subclasses 2017-11-24 15:11:29 +01:00
bors-servo 40165e7876 Auto merge of #129 - faern:higher-level-dictionary-find, r=jdm
Higher level dictionary find/contains_key

I'm not very familiar with Core Foundation yet, so tell me if this is not a very helpful addition.

Adding versions of find and contains_key that can take any `TCFType` and automatically converts it to the raw pointer of its corresponding ref type. It looks like dictionaries will mostly contain types implementing this trait, and thus these versions of the methods can make it a bit more ergonomic to use the dictionary. The best would of course be if we could return the correct type as well, but I guess that is not possible with the available information.

Better suggestions for the names are welcome :)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/129)
<!-- Reviewable:end -->
2017-11-23 08:20:47 -06:00
bors-servo a166cee7d1 Auto merge of #130 - faern:runloop-source-and-observer, r=jdm
Add runloop source and observer functionality

I had the need to add a source (from `SCDynamicStoreCreateRunLoopSource`). And since all the add/contains/remove operations were fairly trivial I did not see any reason to not complete them for timers, sources and observers at the same time.

Also adding the `CFRunLoopMode` type alias to make the signatures reflect the original API a bit more.

Lastly, removing underscore from `_info` since it's actually used.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/130)
<!-- Reviewable:end -->
2017-11-23 08:07:22 -06:00
Linus Färnstrand 7468b455c7 Add runloop source and observer functionality 2017-11-23 13:07:15 +01:00
Linus Färnstrand c445b6e938 Simplify CFDictionary::get with expect() 2017-11-22 20:21:25 +01:00
Linus Färnstrand 64d944780a Simplify and document CFDictionary::get 2017-11-22 16:31:50 +01:00
Linus Färnstrand a076397614 Add higher level methods to CFDictionary 2017-11-22 16:31:50 +01:00
bors-servo 36fad2dbda Auto merge of #128 - faern:impl-from-cfstring, r=nox
Implement From<&str> for CFString

I'm not sure if you have any strict policies on what types you usually accept as parameters to the safe wrappers. So I'm not sure if you want this or not. But my reasons are:

I create `system-configuration` and `system-configuration-sys` crates as bindings to that API. In the [`SCDynamicStore`] module a lot of the functions take a `CFStringRef` as argument. It would be more ergonomic if this safe wrapper type could deal with Rust strings directly, so I can do:
```rust
let store = SCDynamicStore::create("my-dynamic-store");
let dict = store.find("State:/Network/Global/IPv4");
```
But at the same time I don't want to make it harder to use for people who already sit on `CFString` objects. So with this new `From<&str>` impl my API can be used both with `&str` and `CFString` if I implement the methods as `<S: Into<CFString>>`.

[`SCDynamicStore`]: https://developer.apple.com/documentation/systemconfiguration/scdynamicstore?language=objc

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/128)
<!-- Reviewable:end -->
2017-11-22 08:24:29 -06:00
Linus Färnstrand b8a4536eac Implement From<&str> for CFString 2017-11-22 14:57:31 +01:00
bors-servo 491d6f782e Auto merge of #126 - ratake:date, r=jdm
Add CFDate, CFTimeZone and make them work with chrono

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/126)
<!-- Reviewable:end -->
2017-11-13 09:49:13 -06:00
ratake be2dd253be Make CFDate and CFTimeZone interoperable with the chrono crate 2017-11-12 17:43:31 -08:00
ratake 7b6fbdb1a1 Added support for CFTimeZone objects 2017-11-12 17:43:31 -08:00
ratake 79cd89bd5d Added support for CFDate objects 2017-11-12 17:43:31 -08:00
ratake e3fc4fe3e4 Implement Debug for all types 2017-11-12 17:41:29 -08:00
bors-servo fda0928c53 Auto merge of #124 - ratake:uuid-crate, r=jdm
Made CFUUID interoperable with the uuid crate

Behind the `with-uuid` feature

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/124)
<!-- Reviewable:end -->
2017-11-08 07:58:55 -06:00
bors-servo fe0900d73c Auto merge of #123 - ratake:clone-ord-eq, r=jdm
Implement Clone + Eq for all types, Ord for CFNumber

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/123)
<!-- Reviewable:end -->
2017-11-08 07:35:03 -06:00
bors-servo 223a0d3a0a Auto merge of #125 - ratake:exact-iterator, r=jdm
Implement ExactSizeIterator for CFArrayIterator

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/125)
<!-- Reviewable:end -->
2017-11-08 07:18:08 -06:00
ratake 8759071ea7 Implement ExactSizeIterator for CFArrayIterator 2017-11-07 20:58:27 -08:00
ratake b81cfce569 Made CFUUID interoperable with the uuid crate 2017-11-07 20:49:25 -08:00
ratake 2e2e6af6d8 Implement Ord for CFNumber 2017-11-07 20:44:13 -08:00
ratake 933b235901 Implement Clone for all types
Not just CFString
2017-11-07 20:44:13 -08:00
ratake d20b8abc9c Implement Eq for all types 2017-11-07 20:44:12 -08:00
bors-servo a1125852db Auto merge of #122 - jrmuizel:to-path, r=jdm
Implement to_path() to convert CFURLs to PathBufs.

This lets us roundtrip Paths through CFURLs

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/122)
<!-- Reviewable:end -->
2017-10-20 13:44:36 -05:00
Jeff Muizelaar 21a2dde8c6 Implement to_path() to convert CFURLs to PathBufs.
This lets us roundtrip Paths through CFURLs
2017-10-20 14:39:45 -04:00
bors-servo 2ceebd44fe Auto merge of #121 - jrmuizel:uuid, r=jdm
Add support for CFUUID

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/121)
<!-- Reviewable:end -->
2017-10-20 10:46:12 -05:00
bors-servo dd3b248259 Auto merge of #119 - jrmuizel:cfurl-fs, r=jdm
Add CFURLGetFileSystemRepresentation

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/119)
<!-- Reviewable:end -->
2017-10-20 07:49:22 -05:00
bors-servo f3a0624bf5 Auto merge of #120 - jrmuizel:path-buf2, r=SimonSapin
Support converting non-utf8 paths to CFURLs

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/120)
<!-- Reviewable:end -->
2017-10-20 02:34:58 -05:00
Jeff Muizelaar 6ca30dd9a8 Add support for CFUUID 2017-10-19 22:29:25 -04:00
Jeff Muizelaar a6dc32cf50 Support converting non-utf8 paths to CFURLs 2017-10-19 18:17:26 -04:00
Jeff Muizelaar 04fd67e25b Add CFURLGetFileSystemRepresentation 2017-10-19 17:36:54 -04:00
bors-servo b9245f7e9b Auto merge of #118 - ratake:master, r=jdm
Filling in more of the API surface

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/118)
<!-- Reviewable:end -->
2017-10-13 00:38:01 -05:00
ratake 0dd90e84ae Complete the CFAllocator reference 2017-10-12 21:48:29 -07:00