woboq / qmetaobject-rs

Integrate Qml and Rust by building the QMetaObject at compile time.
MIT License
620 stars 89 forks source link

QObjectBox struct is redundant? #170

Open ratijas opened 3 years ago

ratijas commented 3 years ago

QObjectBox is only ever used for the old kefia example in a form of a patch.

Seems like the functionality was superseded by QObjectPinned, except there is no lifetime, and content is owned. I wonder, if there is any use for it?

Searching 73 files for "QObjectBox"

/qt/qmetaobject-rs/examples/kefia/0002-Port-to-qmetaobject-rs.patch:
   91   
   92  -    let qpckgs = QPackages::new(Packages {
   93: +    let qpckgs = QObjectBox::new(Packages {
   94           vec: gathered,
   95           list: list,

/qt/qmetaobject-rs/qmetaobject/src/lib.rs:
  214      pub use crate::{
  215          qml_register_type, qrc, qt_base_class, qt_method, qt_plugin, qt_property, qt_signal,
  216:         QAbstractListModel, QByteArray, QColor, QDate, QDateTime, QModelIndex, QObject, QObjectBox,
  217          QPointer, QQmlExtensionPlugin, QQuickItem, QQuickView, QRectF, QString, QTime, QVariant,
  218          QmlEngine,
  ...
  543  
  544  /// A wrapper around RefCell<T>, whose content cannot be move in memory
  545: pub struct QObjectBox<T: QObject + ?Sized>(Box<RefCell<T>>);
  546  
  547: impl<T: QObject> QObjectBox<T> {
  548      pub fn new(obj: T) -> Self {
  549:         QObjectBox(Box::new(RefCell::new(obj)))
  550      }
  551  }
  552  
  553: impl<T: QObject + Default> Default for QObjectBox<T> {
  554      fn default() -> Self {
  555          Self::new(Default::default())
  ...
  557  }
  558  
  559: impl<T: QObject + ?Sized> QObjectBox<T> {
  560      pub fn pinned(&self) -> QObjectPinned<T> {
  561          unsafe { QObjectPinned::new(&self.0) }
ogoffart commented 3 years ago

I don't remember, but you're probably right.

Note that also QObjectPinned should be changed to use std::Pin now, that did not exist at the time this API was developed.

ratijas commented 3 years ago

Note that also QObjectPinned should be changed to use std::Pin now, that did not exist at the time this API was developed.

Yes, I'll get to it someday too. Before that, I'd want to clean up more things.