Skip to content

Commit 8a983b0

Browse files
committed
glib: Deprecate suboptimal Object constructors
1 parent e44e65b commit 8a983b0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

gio/src/async_initable.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ impl AsyncInitable {
1616
#[allow(clippy::new_ret_no_self)]
1717
#[doc(alias = "g_async_initable_new_async")]
1818
#[track_caller]
19+
#[deprecated = "Use AsyncInitable::builder() or AsyncInitable::new_default() instead"]
20+
#[allow(deprecated)]
1921
pub fn new<
2022
O: IsClass + IsA<Object> + IsA<AsyncInitable>,
2123
Q: FnOnce(Result<O, glib::Error>) + 'static,
@@ -41,6 +43,8 @@ impl AsyncInitable {
4143
/// `AsyncInitable::init` failed.
4244
#[doc(alias = "g_async_initable_new_async")]
4345
#[track_caller]
46+
#[deprecated = "Use AsyncInitable::builder() or AsyncInitable::new_default_future() instead"]
47+
#[allow(deprecated)]
4448
pub fn new_future<O: IsClass + IsA<Object> + IsA<AsyncInitable>>(
4549
properties: &[(&str, &dyn ToValue)],
4650
io_priority: glib::Priority,
@@ -58,6 +62,7 @@ impl AsyncInitable {
5862
/// `AsyncInitable::init` failed.
5963
#[doc(alias = "g_async_initable_new_async")]
6064
#[track_caller]
65+
#[deprecated = "Use AsyncInitable::builder() or AsyncInitable::new_default_with_type() instead"]
6166
pub fn with_type<Q: FnOnce(Result<Object, glib::Error>) + 'static>(
6267
type_: Type,
6368
properties: &[(&str, &dyn ToValue)],
@@ -93,6 +98,7 @@ impl AsyncInitable {
9398
/// `AsyncInitable::init` failed.
9499
#[doc(alias = "g_async_initable_new_async")]
95100
#[track_caller]
101+
#[deprecated = "Use AsyncInitable::builder() or AsyncInitable::new_default_future() instead"]
96102
pub fn with_type_future(
97103
type_: Type,
98104
properties: &[(&str, &dyn ToValue)],
@@ -230,6 +236,7 @@ impl AsyncInitable {
230236
/// `AsyncInitable::init` failed.
231237
#[doc(alias = "g_async_initable_new_async")]
232238
#[track_caller]
239+
#[deprecated = "Use AsyncInitable::with_mut_values() instead"]
233240
pub fn with_values<Q: FnOnce(Result<Object, glib::Error>) + 'static>(
234241
type_: Type,
235242
properties: &[(&str, glib::Value)],
@@ -265,6 +272,7 @@ impl AsyncInitable {
265272
/// `AsyncInitable::init` failed.
266273
#[doc(alias = "g_async_initable_new_async")]
267274
#[track_caller]
275+
#[deprecated = "Use AsyncInitable::with_mut_values_future() instead"]
268276
pub fn with_values_future(
269277
type_: Type,
270278
properties: &[(&str, glib::Value)],

gio/src/initable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ impl Initable {
1414
/// `Initable::init` failed.
1515
#[allow(clippy::new_ret_no_self)]
1616
#[track_caller]
17+
#[deprecated = "Use Initable::builder() or Initable::new_default() instead"]
18+
#[allow(deprecated)]
1719
pub fn new<O: IsClass + IsA<Object> + IsA<Initable>>(
1820
properties: &[(&str, &dyn ToValue)],
1921
cancellable: Option<&impl IsA<Cancellable>>,
@@ -28,6 +30,7 @@ impl Initable {
2830
/// Similar to [`Object::with_type`] but can fail because the object initialization in
2931
/// `Initable::init` failed.
3032
#[track_caller]
33+
#[deprecated = "Use Initable::builder() or Initable::new_default_with_type() instead"]
3134
pub fn with_type(
3235
type_: Type,
3336
properties: &[(&str, &dyn ToValue)],
@@ -89,6 +92,7 @@ impl Initable {
8992
/// Similar to [`Object::with_values`] but can fail because the object initialization in
9093
/// `Initable::init` failed.
9194
#[track_caller]
95+
#[deprecated = "Use Initable::with_mut_values() instead"]
9296
pub fn with_values(
9397
type_: Type,
9498
properties: &[(&str, glib::Value)],

glib/src/object.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,8 @@ impl Object {
13521352
/// property values of the wrong type are provided.
13531353
#[allow(clippy::new_ret_no_self)]
13541354
#[track_caller]
1355+
#[deprecated = "Use Object::builder() or Object::new_default() instead"]
1356+
#[allow(deprecated)]
13551357
pub fn new<T: IsA<Object> + IsClass>(properties: &[(&str, &dyn ToValue)]) -> T {
13561358
let object = Object::with_type(T::static_type(), properties);
13571359
unsafe { object.unsafe_cast() }
@@ -1365,6 +1367,7 @@ impl Object {
13651367
/// This panics if the object is not instantiable, doesn't have all the given properties or
13661368
/// property values of the wrong type are provided.
13671369
#[track_caller]
1370+
#[deprecated = "Use Object::builder_with_type() or Object::new_default_with_type() instead"]
13681371
pub fn with_type(type_: Type, properties: &[(&str, &dyn ToValue)]) -> Object {
13691372
#[cfg(feature = "gio")]
13701373
unsafe {
@@ -1412,11 +1415,15 @@ impl Object {
14121415
// rustdoc-stripper-ignore-next
14131416
/// Create a new instance of an object of the given type with the given properties.
14141417
///
1418+
/// If possible call [`with_mut_values`] instead as this function has to take copies of all
1419+
/// values before constructing the object.
1420+
///
14151421
/// # Panics
14161422
///
14171423
/// This panics if the object is not instantiable, doesn't have all the given properties or
14181424
/// property values of the wrong type are provided.
14191425
#[track_caller]
1426+
#[deprecated = "Use Object::with_mut_values()` instead"]
14201427
pub fn with_values(type_: Type, properties: &[(&str, Value)]) -> Object {
14211428
#[cfg(feature = "gio")]
14221429
unsafe {

0 commit comments

Comments
 (0)