mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-25 13:43:50 +00:00
Implement ptr_eq for VWeak and PartialEq for Items (#976)
* Implement ptr_eq for VWeaks Co-authored-by: Simon Hausmann <simon.hausmann@slint-ui.com>
This commit is contained in:
parent
6795d3ee00
commit
f3feab1267
15 changed files with 65 additions and 13 deletions
|
|
@ -24,7 +24,7 @@ i-slint-compiler = { version = "=0.2.1", path="../../../internal/compiler" }
|
|||
i-slint-core = { version = "=0.2.1", path="../../../internal/core" }
|
||||
slint-interpreter = { version = "=0.2.1", path="../../../internal/interpreter", features = ["display-diagnostics"] }
|
||||
|
||||
vtable = { version = "0.1.1", path="../../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path="../../../helper_crates/vtable" }
|
||||
|
||||
css-color-parser2 = "1.0.1"
|
||||
generativity = "1"
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ i-slint-backend-selector = { version = "=0.2.1", path="../../../internal/backend
|
|||
|
||||
const-field-offset = { version = "0.1.2", path = "../../../helper_crates/const-field-offset" }
|
||||
document-features = { version = "0.2.0", optional = true }
|
||||
vtable = { version = "0.1.5", path = "../../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path = "../../../helper_crates/vtable" }
|
||||
|
||||
once_cell = { version = "1.5", default-features = false, features = ["alloc"] }
|
||||
pin-weak = { version = "1.1", default-features = false }
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
slint-interpreter = { path = "../../internal/interpreter" }
|
||||
|
||||
vtable = { version = "0.1.1", path="../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path="../../helper_crates/vtable" }
|
||||
|
||||
console_error_panic_hook = { version = "0.1.6", optional = true }
|
||||
js-sys = "0.3.44"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
# Changelog
|
||||
All notable changes to this crate will be documented in this file.
|
||||
|
||||
## [0.1.6] - 2022-02-21
|
||||
|
||||
- Add `VWeak::ptr_eq`
|
||||
|
||||
## [0.1.5] - 2022-01-21
|
||||
|
||||
- Make it `#[no_std]`
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
[package]
|
||||
name = "vtable"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
authors = ["Slint Developers <info@slint-ui.com>"]
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-only OR LicenseRef-Slint-commercial"
|
||||
|
|
@ -14,7 +14,7 @@ homepage = "https://slint-ui.com"
|
|||
[lib]
|
||||
|
||||
[dependencies]
|
||||
vtable-macro = { version = "=0.1.5", path = "./macro" }
|
||||
vtable-macro = { version = "=0.1.6", path = "./macro" }
|
||||
const-field-offset = { version = "0.1", path = "../const-field-offset" }
|
||||
stable_deref_trait = { version = "1.2.0", default-features = false }
|
||||
atomic-polyfill = "0.1.5"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
[package]
|
||||
name = "vtable-macro"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
authors = ["Slint Developers <info@slint-ui.com>"]
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-only OR LicenseRef-Slint-commercial"
|
||||
|
|
|
|||
|
|
@ -313,6 +313,11 @@ impl<VTable: VTableMetaDropInPlace + 'static, X> VWeak<VTable, X> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the two VWeak instances point to the same allocation
|
||||
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
|
||||
this.inner == other.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<VTable: VTableMetaDropInPlace + 'static, X: HasStaticVTable<VTable> + 'static>
|
||||
|
|
|
|||
|
|
@ -254,3 +254,38 @@ fn rc_map_origin() {
|
|||
|
||||
assert!(weak_origin.upgrade().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ptr_eq() {
|
||||
let string = Rc::new("hello".to_string());
|
||||
|
||||
let vrc1 = VRc::new(SomeStruct { e: 42, x: "42".into(), foo: string.clone() });
|
||||
let vweak1 = VRc::downgrade(&vrc1);
|
||||
|
||||
let vrc2 = VRc::new(SomeStruct { e: 23, x: "23".into(), foo: string });
|
||||
let vweak2 = VRc::downgrade(&vrc2);
|
||||
|
||||
let vweak1clone = vweak1.clone();
|
||||
let vrc2clone = vrc2.clone();
|
||||
let vweak2clone = VRc::downgrade(&vrc2clone);
|
||||
|
||||
assert!(VRc::ptr_eq(&vrc2, &vrc2clone));
|
||||
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak1, &vweak1));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak1clone, &vweak1clone));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak1clone, &vweak1));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak1, &vweak1clone));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak2clone, &vweak2));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak2, &vweak2clone));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak2, &vweak2));
|
||||
assert!(vtable::VWeak::ptr_eq(&vweak2clone, &vweak2clone));
|
||||
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak1clone, &vweak2));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak1clone, &vweak2clone));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak1, &vweak2));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak1, &vweak2clone));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak2clone, &vweak1));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak2clone, &vweak1clone));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak2, &vweak1));
|
||||
assert!(!vtable::VWeak::ptr_eq(&vweak2, &vweak1clone));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ i-slint-core = { version = "=0.2.1", path = "../../../internal/core" }
|
|||
i-slint-common = { version = "=0.2.1", path = "../../../internal/common" }
|
||||
|
||||
const-field-offset = { version = "0.1", path = "../../../helper_crates/const-field-offset" }
|
||||
vtable = { version = "0.1", path = "../../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path = "../../../helper_crates/vtable" }
|
||||
|
||||
by_address = "1.0.4"
|
||||
cfg-if = "1"
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ i-slint-common = { version = "=0.2.1", path = "../../../internal/common", defaul
|
|||
i-slint-core = { version = "=0.2.1", path = "../../../internal/core", default-features = false }
|
||||
|
||||
const-field-offset = { version = "0.1", path = "../../../helper_crates/const-field-offset" }
|
||||
vtable = { version = "0.1", path = "../../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path = "../../../helper_crates/vtable" }
|
||||
|
||||
by_address = "1.0.4"
|
||||
derive_more = "0.99.5"
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ i-slint-core-macros = { version = "=0.2.1", path = "../../../internal/core-macro
|
|||
i-slint-core = { version = "=0.2.1", path = "../../../internal/core" }
|
||||
|
||||
const-field-offset = { version = "0.1", path = "../../../helper_crates/const-field-offset" }
|
||||
vtable = { version = "0.1", path = "../../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path = "../../../helper_crates/vtable" }
|
||||
|
||||
cpp = "0.5.5"
|
||||
euclid = "0.22.1"
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ i-slint-common = { version = "=0.2.1", path = "../common" }
|
|||
i-slint-core-macros = { version = "=0.2.1", path = "../core-macros" }
|
||||
|
||||
const-field-offset = { version = "0.1", path = "../../helper_crates/const-field-offset" }
|
||||
vtable = { version="0.1.1", path = "../../helper_crates/vtable" }
|
||||
vtable = { version="0.1.6", path = "../../helper_crates/vtable" }
|
||||
|
||||
atomic-polyfill = { version = "0.1.5" }
|
||||
auto_enums = "0.7"
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ impl ItemRc {
|
|||
}
|
||||
|
||||
/// A Weak reference to an item that can be constructed from an ItemRc.
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
#[repr(C)]
|
||||
pub struct ItemWeak {
|
||||
component: crate::component::ComponentWeak,
|
||||
|
|
@ -202,6 +202,14 @@ impl ItemWeak {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ItemWeak {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
VWeak::ptr_eq(&self.component, &other.component) && self.index == other.index
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for ItemWeak {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(FieldOffsets, Default, SlintElement)]
|
||||
#[pin]
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ i-slint-compiler = { version = "=0.2.1", path = "../compiler" }
|
|||
i-slint-core = { version = "=0.2.1", path = "../core", features = ["rtti"] }
|
||||
i-slint-backend-selector = { version = "=0.2.1", path = "../../internal/backends/selector" }
|
||||
|
||||
vtable = { version = "0.1.1", path="../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path="../../helper_crates/vtable" }
|
||||
|
||||
derive_more = "0.99.5"
|
||||
generativity = "1"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ i-slint-core = { version = "=0.2.1", path="../../internal/core" }
|
|||
slint-interpreter = { version = "=0.2.1", path = "../../internal/interpreter", default-features = false, features = ["display-diagnostics", "compat-0-2-0"] }
|
||||
i-slint-backend-selector = { version = "=0.2.1", path="../../internal/backends/selector" }
|
||||
|
||||
vtable = { version = "0.1", path="../../helper_crates/vtable" }
|
||||
vtable = { version = "0.1.6", path="../../helper_crates/vtable" }
|
||||
|
||||
clap = { version = "3.0.5", features=["derive", "wrap_help"] }
|
||||
codemap = "0.1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue