Skip to content

Commit

Permalink
glib: Add optional support for serialization and deserialization with…
Browse files Browse the repository at this point in the history
… 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 + _>
  • Loading branch information
rmnscnce committed Apr 12, 2023
1 parent 4510666 commit c45eb0b
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- { 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 }
- { name: "gdk-pixbuf", features: "v2_42", nightly: "--all-features", test_sys: true }
- { name: "gio", features: "v2_74", nightly: "--all-features", test_sys: true }
- { name: "glib", features: "v2_74", nightly: "--all-features", test_sys: true }
- { name: "glib", features: "v2_74,serde", nightly: "--all-features", test_sys: true }
- { name: "graphene", features: "", nightly: "", test_sys: true }
- { name: "pango", features: "v1_50", nightly: "--all-features", test_sys: true }
- { name: "pangocairo", features: "", nightly: "--all-features", test_sys: true }
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- { name: "cairo", test: true, args: "--features png,pdf,svg,ps,use_glib,v1_16,freetype,script,win32-surface" }
- { name: "gdk-pixbuf", test: true, args: "--features v2_42" }
- { name: "gio", test: true, args: "--features v2_74" }
- { name: "glib", test: true, args: "--features v2_74" }
- { name: "glib", test: true, args: "--features v2_74,serde" }
- { name: "glib-build-tools", test: false, args: "" }
- { name: "graphene", test: false, args: "" }
- { name: "pango", test: true, args: "--features v1_50" }
Expand Down Expand Up @@ -126,8 +126,15 @@ jobs:
with:
command: test
args: --manifest-path ${{ matrix.conf.name }}/sys/Cargo.toml ${{ matrix.conf.args }}
if: matrix.conf.name != 'examples' && matrix.conf.name != 'glib-build-tools'
if: matrix.conf.name != 'examples' && matrix.conf.name != 'glib' && matrix.conf.name != 'glib-build-tools'

- name: test glib-sys
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path ${{ matrix.conf.name }}/sys/Cargo.toml --features v2_74
if: matrix.conf.name == 'glib'

- name: build
uses: actions-rs/cargo@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions glib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ smallvec = "1.0"
thiserror = "1"
gio_ffi = { package = "gio-sys", path = "../gio/sys", optional = true }
memchr = "2.5.0"
serde = { version = "1.0", optional = true }

[dev-dependencies]
tempfile = "3"
gir-format-check = "^0.1"
trybuild2 = "1"
criterion = "0.4.0"
serde_json = "1.0"

[features]
default = ["gio"]
Expand All @@ -59,6 +61,7 @@ log_macros = ["log"]
dox = ["ffi/dox", "gobject_ffi/dox", "log_macros"]
compiletests = []
gio = ["gio_ffi"]
serde = ["dep:serde"]

[package.metadata.docs.rs]
features = ["dox"]
Expand Down
10 changes: 10 additions & 0 deletions glib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ glib = "0.13"
glib = { git = "https://github.com/gtk-rs/gtk-rs-core.git", package = "glib" }
```

### Serialization with Serde

If you want to serialize (and deserialize) some GLib types (e.g. `GString`) with Serde, you can enable the `serde` feature:

```toml
glib = { version = "0.18", features = ["serde"] }
```

This library implements serialization and deserialization as described in the `serde@^1.0` API.

## License

__glib__ is available under the MIT License, please refer to it.
3 changes: 3 additions & 0 deletions glib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ pub use self::thread_pool::{ThreadHandle, ThreadPool};

pub mod thread_guard;

#[cfg(feature = "serde")]
mod serde;

// rustdoc-stripper-ignore-next
/// This is the log domain used by the [`clone!`][crate::clone!] macro. If you want to use a custom
/// logger (it prints to stdout by default), you can set your own logger using the corresponding
Expand Down
Loading

0 comments on commit c45eb0b

Please sign in to comment.