Need help with some Glib pointers in Rust

I'm beginner in Rust, and can't understand from documentation

  • if I make Byte.clone() for Bytes - it will create just new pointer, not entire bytes slice?
  • same for GString.clone() (GString)

both should be shared pointers with data stored on heap, so I can clone them without worry to take extra space in memory, or must I use reference to these objects instead?

Maybe somebody have experience in GTK and can simply reply for this newbie question

clone is a Rust method. If you're using the glib crate, see:
https://docs.rs/glib/latest/glib/struct.Bytes.html#impl-Clone-for-Bytes
https://docs.rs/glib/latest/glib/struct.GString.html#impl-Clone-for-GString

1 Like

So GString.clone() make the copy of data with same method name (where clone for Bytes makes just reference with counter increased), right?

Yes. I don't see a glib-specific way of sharing GStrings, but I have no glib experience. Wrapping it in a Rust Arc would work.

2 Likes

Thanks for answer, I've read about GSrings once but for some reasons returned again with doubts, because lot of gobjects already shared references :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.