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 59b15e0
Show file tree
Hide file tree
Showing 5 changed files with 630 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ jobs:
- name: build
run: cargo build --manifest-path ${{ matrix.conf.name }}/Cargo.toml --features "${{ matrix.conf.features }}"
if: matrix.rust != 'nightly'
- name: build-serde
run: cargo build --manifest-path ${{ matrix.conf.name }}/Cargo.toml --features "${{ matrix.conf.features }},serde"
if: matrix.rust != 'nightly' && matrix.conf_name == 'glib'
- name: tests
run: cargo test --manifest-path ${{ matrix.conf.name }}/Cargo.toml --features "${{ matrix.conf.features }}"
if: matrix.rust != 'nightly'
- name: test-serde
run: cargo test --manifest-path ${{ matrix.conf.name }}/Cargo.toml --features "${{ matrix.conf.features }},serde"
if: matrix.rust != 'nightly' && matrix.conf_name == 'glib'
- name: Test ${{ matrix.conf.name }}/sys
run: cargo test
working-directory: ${{ matrix.conf.name }}/sys
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 59b15e0

Please sign in to comment.