Skip to content

Commit a75b75d

Browse files
authored
Merge pull request #906 from sdroege/deprecate-obj
glib: Deprecate `ObjectSubclass::instance()` / `from_instance()` in f…
2 parents 8e0d925 + 32ec9ca commit a75b75d

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

glib-macros/src/object_subclass_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn impl_object_subclass(input: &syn::ItemImpl) -> TokenStream {
121121
type FromObjectType = <Self as #crate_ident::subclass::types::ObjectSubclass>::Type;
122122
#[inline]
123123
fn from_object(obj: &Self::FromObjectType) -> &Self {
124-
<Self as #crate_ident::subclass::types::ObjectSubclassExt>::from_instance(obj)
124+
<Self as #crate_ident::subclass::types::ObjectSubclassExt>::from_obj(obj)
125125
}
126126
}
127127

glib/src/subclass/interface.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,16 @@ pub trait ObjectInterfaceExt: ObjectInterface {
127127
///
128128
/// This will panic if `obj` does not implement the interface.
129129
#[inline]
130+
#[deprecated = "Use from_obj() instead"]
130131
fn from_instance<T: IsA<Object>>(obj: &T) -> &Self {
132+
Self::from_obj(obj)
133+
}
134+
135+
/// Get interface from an instance.
136+
///
137+
/// This will panic if `obj` does not implement the interface.
138+
#[inline]
139+
fn from_obj<T: IsA<Object>>(obj: &T) -> &Self {
131140
assert!(obj.as_ref().type_().is_a(Self::type_()));
132141

133142
unsafe {

glib/src/subclass/object_impl_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<T: ObjectSubclass> std::ops::Deref for ObjectImplRef<T> {
5555

5656
#[inline]
5757
fn deref(&self) -> &Self::Target {
58-
T::from_instance(&self.0)
58+
T::from_obj(&self.0)
5959
}
6060
}
6161

glib/src/subclass/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub trait ObjectSubclassIsExt: ObjectSubclassIs {
119119
impl<T: ObjectSubclassIs<Subclass = S>, S: ObjectSubclass<Type = Self>> ObjectSubclassIsExt for T {
120120
#[inline]
121121
fn imp(&self) -> &T::Subclass {
122-
T::Subclass::from_instance(self)
122+
T::Subclass::from_obj(self)
123123
}
124124
}
125125

@@ -665,10 +665,12 @@ pub trait ObjectSubclassExt: ObjectSubclass {
665665
// rustdoc-stripper-ignore-next
666666
/// Returns the corresponding object instance.
667667
#[doc(alias = "get_instance")]
668+
#[deprecated = "Use obj() instead"]
668669
fn instance(&self) -> crate::BorrowedObject<Self::Type>;
669670

670671
// rustdoc-stripper-ignore-next
671672
/// Returns the implementation from an instance.
673+
#[deprecated = "Use from_obj() instead"]
672674
fn from_instance(obj: &Self::Type) -> &Self;
673675

674676
// rustdoc-stripper-ignore-next

0 commit comments

Comments
 (0)