Skip to content

Commit a28324c

Browse files
committed
Updated src/provider/imp.rs:
- Updated reuse copyright year - Added clearer import headers - Refactored to now import std::sync::OncelLock as it has been [merged into std](rust-lang/rust#105587) - Added import of Value from glib::value - Refactored "properties()" function to reflect OnceLock changes - Removed now unused "_obj" parameter to "property()" and "set_property()" functions Updated src/provider/mod.rs: - Updated reuse copyright year - Added clearer import headers - Updated "new()" function to use "Object::builder::<Provider>().build()" instead of untyped "Obect::new()"" Signed-off-by: Deren Vural <[email protected]>
1 parent 8de4b47 commit a28324c

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

src/provider/imp.rs

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

4-
use adwaita::glib;
54
/**
65
* Name:
76
* imp.rs
@@ -19,9 +18,20 @@ use adwaita::glib;
1918
*
2019
*/
2120
// Imports
22-
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
23-
use gtk::{prelude::*, subclass::prelude::*};
24-
use std::{cell::Cell, cell::RefCell};
21+
// std
22+
use std::sync::OnceLock;
23+
use std::cell::{
24+
Cell, RefCell
25+
};
26+
// gtk-rs
27+
use gtk::{
28+
prelude::*, subclass::prelude::*
29+
};
30+
use adwaita::glib;
31+
use glib::{
32+
ParamSpec,
33+
value::Value
34+
};
2535

2636
// Modules
2737
use crate::property::Property;
@@ -86,13 +96,15 @@ impl ObjectImpl for Provider {
8696
* glib::ParamSpecObject::builder("formatter").build(),
8797
*/
8898
fn properties() -> &'static [ParamSpec] {
89-
static PROPERTIES: Lazy<Vec<ParamSpec>> =
90-
Lazy::new(|| vec![glib::ParamSpecInt::builder("provider-type").build()]);
99+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
100+
PROPERTIES.get_or_init(|| {
101+
vec![
102+
glib::ParamSpecInt::builder("provider-type").build()
103+
]
104+
})
91105

92106
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
93107
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
94-
95-
PROPERTIES.as_ref()
96108
}
97109

98110
/**
@@ -111,7 +123,12 @@ impl ObjectImpl for Provider {
111123
* Notes:
112124
*
113125
*/
114-
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
126+
fn set_property(
127+
&self,
128+
_id: usize,
129+
value: &Value,
130+
pspec: &ParamSpec
131+
) {
115132
//println!("setting: {:?}", pspec.name());//TEST
116133

117134
match pspec.name() {
@@ -141,7 +158,11 @@ impl ObjectImpl for Provider {
141158
* Notes:
142159
*
143160
*/
144-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
161+
fn property(
162+
&self,
163+
_id: usize,
164+
pspec: &ParamSpec
165+
) -> Value {
145166
//println!("getting: {:?}", pspec.name());//TEST
146167

147168
match pspec.name() {

src/provider/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
/**
@@ -21,11 +21,19 @@
2121
mod imp;
2222

2323
// Imports
24-
use adwaita::{gio, glib};
25-
use gio::{Cancellable, Settings};
26-
use glib::Object;
27-
use gtk::{prelude::*, subclass::prelude::*};
24+
// std
2825
use std::ffi::OsStr;
26+
// gtk-rs
27+
use gtk::{
28+
prelude::*, subclass::prelude::*
29+
};
30+
use adwaita::{
31+
gio, glib
32+
};
33+
use gio::{
34+
Cancellable, Settings
35+
};
36+
use glib::Object;
2937

3038
// Crates
3139
use crate::{
@@ -78,7 +86,8 @@ impl Provider {
7886
*
7987
*/
8088
pub fn new(func: fn() -> Vec<Property>, provider_type: i32) -> Self {
81-
let obj: Provider = Object::new(&[]).expect("Failed to create `Provider`");
89+
// Create Object
90+
let obj: Provider = Object::builder::<Provider>().build();
8291

8392
// Set type of provider
8493
obj.set_property("provider-type", provider_type);

0 commit comments

Comments
 (0)