Skip to content

Commit 407d50b

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 4510666 commit 407d50b

File tree

4 files changed

+416
-0
lines changed

4 files changed

+416
-0
lines changed

glib/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ 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"
@@ -59,6 +60,7 @@ log_macros = ["log"]
5960
dox = ["ffi/dox", "gobject_ffi/dox", "log_macros"]
6061
compiletests = []
6162
gio = ["gio_ffi"]
63+
serde = ["dep:serde"]
6264

6365
[package.metadata.docs.rs]
6466
features = ["dox"]

glib/README.md

+10
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

+3
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)