Skip to content

Commit abe5dfd

Browse files
committed
glib: Add optional support for serialization and deserialization with serde
This feature is gated as `serde` Supports both serialization and deserialization: - glib::Bytes - glib::GString (with in-place deserialization) Supports serialization only: - glib::ByteArray - glib::GStr - glib::StrV Collection types are also supported as long as the type parameters implement the necessary traits: - glib::Slice<T: TransparentType + _> - glib::PtrSlice<T: TransparentPtrType + _> - glib::List<T: TransparentPtrType + _> - glib::SList<T: TransparentPtrType + _>
1 parent bd8457f commit abe5dfd

File tree

6 files changed

+632
-3
lines changed

6 files changed

+632
-3
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- { name: "cairo", features: "png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface", nightly: "--features 'png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface'", test_sys: true }
2424
- { name: "gdk-pixbuf", features: "v2_42", nightly: "--all-features", test_sys: true }
2525
- { name: "gio", features: "v2_74", nightly: "--all-features", test_sys: true }
26-
- { name: "glib", features: "v2_74", nightly: "--all-features", test_sys: true }
26+
- { name: "glib", features: "v2_74,serde", nightly: "--all-features", test_sys: true }
2727
- { name: "graphene", features: "", nightly: "", test_sys: true }
2828
- { name: "pango", features: "v1_50", nightly: "--all-features", test_sys: true }
2929
- { name: "pangocairo", features: "", nightly: "--all-features", test_sys: true }

.github/workflows/windows.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- { name: "cairo", test: true, args: "--features png,pdf,svg,ps,use_glib,v1_16,freetype,script,win32-surface" }
8282
- { name: "gdk-pixbuf", test: true, args: "--features v2_42" }
8383
- { name: "gio", test: true, args: "--features v2_74" }
84-
- { name: "glib", test: true, args: "--features v2_74" }
84+
- { name: "glib", test: true, args: "--features v2_74,serde" }
8585
- { name: "glib-build-tools", test: false, args: "" }
8686
- { name: "graphene", test: false, args: "" }
8787
- { name: "pango", test: true, args: "--features v1_50" }
@@ -126,8 +126,15 @@ jobs:
126126
with:
127127
command: test
128128
args: --manifest-path ${{ matrix.conf.name }}/sys/Cargo.toml ${{ matrix.conf.args }}
129-
if: matrix.conf.name != 'examples' && matrix.conf.name != 'glib-build-tools'
129+
if: matrix.conf.name != 'examples' && matrix.conf.name != 'glib' && matrix.conf.name != 'glib-build-tools'
130130

131+
- name: test glib-sys
132+
uses: actions-rs/cargo@v1
133+
with:
134+
command: test
135+
args: --manifest-path ${{ matrix.conf.name }}/sys/Cargo.toml --features v2_74
136+
if: matrix.conf.name == 'glib'
137+
131138
- name: build
132139
uses: actions-rs/cargo@v1
133140
with:

glib/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ smallvec = "1.0"
3535
thiserror = "1"
3636
gio_ffi = { package = "gio-sys", path = "../gio/sys", optional = true }
3737
memchr = "2.5.0"
38+
serde = { version = "1.0", optional = true }
3839

3940
[dev-dependencies]
4041
tempfile = "3"
4142
gir-format-check = "^0.1"
4243
trybuild2 = "1"
4344
criterion = "0.4.0"
45+
serde_json = "1.0"
4446

4547
[features]
4648
default = ["gio"]
@@ -59,6 +61,7 @@ log_macros = ["log"]
5961
dox = ["ffi/dox", "gobject_ffi/dox", "log_macros"]
6062
compiletests = []
6163
gio = ["gio_ffi"]
64+
serde = ["dep:serde"]
6265

6366
[package.metadata.docs.rs]
6467
features = ["dox"]

glib/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ glib = "0.13"
9696
glib = { git = "https://github.com/gtk-rs/gtk-rs-core.git", package = "glib" }
9797
```
9898

99+
### Serialization with Serde
100+
101+
If you want to serialize (and deserialize) some GLib types (e.g. `GString`) with Serde, you can enable the `serde` feature:
102+
103+
```toml
104+
glib = { version = "0.18", features = ["serde"] }
105+
```
106+
107+
This library implements serialization and deserialization as described in the `serde@^1.0` API.
108+
99109
## License
100110

101111
__glib__ is available under the MIT License, please refer to it.

glib/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ pub use self::thread_pool::{ThreadHandle, ThreadPool};
213213

214214
pub mod thread_guard;
215215

216+
#[cfg(feature = "serde")]
217+
mod serde;
218+
216219
// rustdoc-stripper-ignore-next
217220
/// This is the log domain used by the [`clone!`][crate::clone!] macro. If you want to use a custom
218221
/// logger (it prints to stdout by default), you can set your own logger using the corresponding

0 commit comments

Comments
 (0)