Skip to content

Commit

Permalink
glib: Cleanup prelude traits
Browse files Browse the repository at this point in the history
By moving all the necessary traits to prelude so that we can simplify
code generation to make use of that instead of having to include a lot
of traits manually
  • Loading branch information
bilelmoussaoui committed Jan 31, 2024
1 parent a4a1688 commit eaff2e9
Show file tree
Hide file tree
Showing 66 changed files with 225 additions and 241 deletions.
4 changes: 2 additions & 2 deletions cairo/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::Error;
#[cfg(feature = "use_glib")]
macro_rules! gvalue_impl {
($name:ty, $get_type:expr) => {
impl glib::types::StaticType for $name {
impl glib::prelude::StaticType for $name {
#[inline]
fn static_type() -> glib::Type {
unsafe { from_glib($get_type()) }
Expand Down Expand Up @@ -40,7 +40,7 @@ macro_rules! gvalue_impl {
}

fn value_type(&self) -> glib::Type {
<Self as glib::StaticType>::static_type()
<Self as glib::prelude::StaticType>::static_type()
}
}

Expand Down
12 changes: 6 additions & 6 deletions cairo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ macro_rules! gvalue_impl_inner {
#[allow(unused_imports)]
use glib::translate::*;

impl glib::types::StaticType for $name {
impl glib::prelude::StaticType for $name {
#[inline]
fn static_type() -> glib::types::Type {
unsafe { from_glib($get_type()) }
Expand Down Expand Up @@ -75,7 +75,7 @@ macro_rules! gvalue_impl {
fn to_value(&self) -> glib::Value {
unsafe {
let mut value = glib::Value::from_type_unchecked(
<$name as glib::StaticType>::static_type(),
<$name as glib::prelude::StaticType>::static_type(),
);
glib::gobject_ffi::g_value_take_boxed(
value.to_glib_none_mut().0,
Expand All @@ -86,15 +86,15 @@ macro_rules! gvalue_impl {
}

fn value_type(&self) -> glib::Type {
<$name as glib::StaticType>::static_type()
<$name as glib::prelude::StaticType>::static_type()
}
}

impl From<$name> for glib::Value {
fn from(v: $name) -> Self {
unsafe {
let mut value = glib::Value::from_type_unchecked(
<$name as glib::StaticType>::static_type(),
<$name as glib::prelude::StaticType>::static_type(),
);
glib::gobject_ffi::g_value_take_boxed(
value.to_glib_none_mut().0,
Expand Down Expand Up @@ -160,7 +160,7 @@ macro_rules! gvalue_impl_inline {
glib::ffi::g_malloc0(std::mem::size_of::<$ffi_name>()) as *mut $ffi_name;
ptr.write(self.0);
let mut value = glib::Value::from_type_unchecked(
<$name as glib::StaticType>::static_type(),
<$name as glib::prelude::StaticType>::static_type(),
);
glib::gobject_ffi::g_value_take_boxed(
value.to_glib_none_mut().0,
Expand All @@ -171,7 +171,7 @@ macro_rules! gvalue_impl_inline {
}

fn value_type(&self) -> glib::Type {
<$name as glib::StaticType>::static_type()
<$name as glib::prelude::StaticType>::static_type()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/pixbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{future::Future, io::Read, mem, path::Path, pin::Pin, ptr, slice};

use glib::{object::IsA, translate::*, Error};
use glib::{prelude::*, translate::*, Error};
use libc::{c_uchar, c_void};

use crate::{Colorspace, Pixbuf, PixbufFormat};
Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/pixbuf_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{ptr, time::SystemTime};

use glib::{object::IsA, translate::*};
use glib::{prelude::*, translate::*};

use crate::{PixbufAnimation, PixbufAnimationIter};

Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/subclass/pixbuf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`PixbufLoader`](crate::PixbufLoader).
use glib::{subclass::prelude::*, translate::*, Cast};
use glib::{prelude::*, subclass::prelude::*, translate::*};

use crate::PixbufLoader;

Expand Down
2 changes: 1 addition & 1 deletion gio/src/dbus_method_invocation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{error::ErrorDomain, translate::*};
use glib::{prelude::*, translate::*};

use crate::DBusMethodInvocation;

Expand Down
2 changes: 1 addition & 1 deletion gio/src/debug_controller_dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod sealed {

pub trait DebugControllerDBusExtManual: sealed::Sealed + IsA<DebugControllerDBus> + Sized {
fn connection(&self) -> DBusConnection {
glib::ObjectExt::property(self.as_ref(), "connection")
ObjectExt::property(self.as_ref(), "connection")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gio/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
time::{Duration, SystemTime},
};

use glib::{translate::*, IntoStrV, StrV};
use glib::{translate::*, StrV};

use crate::FileInfo;

Expand Down
2 changes: 1 addition & 1 deletion gio/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{prelude::*, translate::*, variant::FromVariant, BoolError, IntoStrV, StrV, Variant};
use glib::{prelude::*, translate::*, BoolError, StrV, Variant};

use crate::{prelude::*, Settings, SettingsBindFlags};

Expand Down
2 changes: 1 addition & 1 deletion gio/src/simple_proxy_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{prelude::*, translate::*, IntoStrV};
use glib::{prelude::*, translate::*};

use crate::{ProxyResolver, SimpleProxyResolver};

Expand Down
4 changes: 2 additions & 2 deletions gio/src/socket_msg_flags.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{bitflags, prelude::*, translate::*, value::FromValue, Type};
use glib::{bitflags, prelude::*, translate::*, Type};

bitflags::bitflags! {
#[doc(alias = "GSocketMsgFlags")]
Expand Down Expand Up @@ -46,7 +46,7 @@ impl glib::value::ValueType for SocketMsgFlags {
type Type = Self;
}

unsafe impl<'a> FromValue<'a> for SocketMsgFlags {
unsafe impl<'a> glib::value::FromValue<'a> for SocketMsgFlags {
type Checker = glib::value::GenericValueTypeChecker<Self>;

unsafe fn from_value(value: &'a glib::Value) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion gio/src/subclass/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{ffi::OsString, fmt, ops::Deref, ptr};

use glib::{subclass::prelude::*, translate::*, Cast, ExitCode, VariantDict};
use glib::{prelude::*, subclass::prelude::*, translate::*, ExitCode, VariantDict};
use libc::{c_char, c_int, c_void};

use crate::Application;
Expand Down
2 changes: 1 addition & 1 deletion gio/src/subclass/input_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::ptr;

use glib::{subclass::prelude::*, translate::*, Cast, Error};
use glib::{prelude::*, subclass::prelude::*, translate::*, Error};

use crate::{Cancellable, InputStream};

Expand Down
2 changes: 1 addition & 1 deletion gio/src/subclass/io_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{ptr, sync::OnceLock};

use glib::{prelude::*, subclass::prelude::*, translate::*, Cast, Error};
use glib::{prelude::*, subclass::prelude::*, translate::*, Error};

use crate::{Cancellable, IOStream, InputStream, OutputStream};

Expand Down
2 changes: 1 addition & 1 deletion gio/src/subclass/output_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::ptr;

use glib::{subclass::prelude::*, translate::*, Cast, Error};
use glib::{prelude::*, subclass::prelude::*, translate::*, Error};

use crate::{Cancellable, InputStream, OutputStream, OutputStreamSpliceFlags};

Expand Down
2 changes: 1 addition & 1 deletion gio/src/subclass/seekable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::ptr;

use glib::{subclass::prelude::*, translate::*, Cast, Error, SeekType};
use glib::{prelude::*, subclass::prelude::*, translate::*, Error, SeekType};

use crate::{Cancellable, Seekable};

Expand Down
2 changes: 1 addition & 1 deletion gio/src/subclass/socket_control_message.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{subclass::prelude::*, translate::*, Cast};
use glib::{prelude::*, subclass::prelude::*, translate::*};

use crate::SocketControlMessage;

Expand Down
2 changes: 1 addition & 1 deletion gio/src/tls_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ptr;

use glib::prelude::*;
#[cfg(feature = "v2_60")]
use glib::{translate::*, IntoStrV};
use glib::translate::*;

#[cfg(feature = "v2_66")]
use crate::TlsChannelBindingType;
Expand Down
10 changes: 5 additions & 5 deletions glib-macros/src/boxed_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result<TokenStream> {
const NAME: &'static ::core::primitive::str = #gtype_name;
}

impl #crate_ident::StaticType for #name {
impl #crate_ident::prelude::StaticType for #name {
#[inline]
fn static_type() -> #crate_ident::Type {
static TYPE: ::std::sync::OnceLock<#crate_ident::Type> = ::std::sync::OnceLock::new();
Expand All @@ -151,7 +151,7 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result<TokenStream> {
fn to_value(&self) -> #crate_ident::Value {
unsafe {
let ptr: *mut #name = ::std::boxed::Box::into_raw(::std::boxed::Box::new(self.clone()));
let mut value = #crate_ident::Value::from_type_unchecked(<#name as #crate_ident::StaticType>::static_type());
let mut value = #crate_ident::Value::from_type_unchecked(<#name as #crate_ident::prelude::StaticType>::static_type());
#crate_ident::gobject_ffi::g_value_take_boxed(
#crate_ident::translate::ToGlibPtrMut::to_glib_none_mut(&mut value).0,
ptr as *mut _
Expand All @@ -162,15 +162,15 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result<TokenStream> {

#[inline]
fn value_type(&self) -> #crate_ident::Type {
<#name as #crate_ident::StaticType>::static_type()
<#name as #crate_ident::prelude::StaticType>::static_type()
}
}

impl ::std::convert::From<#name> for #crate_ident::Value {
#[inline]
fn from(v: #name) -> Self {
unsafe {
let mut value = #crate_ident::Value::from_type_unchecked(<#name as #crate_ident::StaticType>::static_type());
let mut value = #crate_ident::Value::from_type_unchecked(<#name as #crate_ident::prelude::StaticType>::static_type());
#crate_ident::gobject_ffi::g_value_take_boxed(
#crate_ident::translate::ToGlibPtrMut::to_glib_none_mut(&mut value).0,
#crate_ident::translate::IntoGlibPtr::<*mut #name>::into_glib_ptr(v) as *mut _,
Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result<TokenStream> {
}
}

impl #crate_ident::HasParamSpec for #name {
impl #crate_ident::prelude::HasParamSpec for #name {
type ParamSpec = #crate_ident::ParamSpecBoxed;
type SetValue = Self;
type BuilderFn = fn(&::core::primitive::str) -> #crate_ident::ParamSpecBoxedBuilder<Self>;
Expand Down
6 changes: 3 additions & 3 deletions glib-macros/src/enum_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn impl_enum(input: &syn::DeriveInput) -> syn::Result<TokenStream> {
}
}

impl #crate_ident::value::ToValue for #name {
impl #crate_ident::prelude::ToValue for #name {
#[inline]
fn to_value(&self) -> #crate_ident::value::Value {
let mut value = #crate_ident::value::Value::for_value_type::<Self>();
Expand All @@ -190,7 +190,7 @@ pub fn impl_enum(input: &syn::DeriveInput) -> syn::Result<TokenStream> {

#[inline]
fn value_type(&self) -> #crate_ident::Type {
<Self as #crate_ident::StaticType>::static_type()
<Self as #crate_ident::prelude::StaticType>::static_type()
}
}

Expand All @@ -201,7 +201,7 @@ pub fn impl_enum(input: &syn::DeriveInput) -> syn::Result<TokenStream> {
}
}

impl #crate_ident::StaticType for #name {
impl #crate_ident::prelude::StaticType for #name {
#[inline]
fn static_type() -> #crate_ident::Type {
Self::register_enum()
Expand Down
4 changes: 2 additions & 2 deletions glib-macros/src/flags_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn impl_flags(attrs: AttrInput, input: &mut syn::ItemEnum) -> TokenStream {

#[inline]
fn value_type(&self) -> #crate_ident::Type {
<Self as #crate_ident::StaticType>::static_type()
<Self as #crate_ident::prelude::StaticType>::static_type()
}
}

Expand All @@ -242,7 +242,7 @@ pub fn impl_flags(attrs: AttrInput, input: &mut syn::ItemEnum) -> TokenStream {
}
}

impl #crate_ident::StaticType for #name {
impl #crate_ident::prelude::StaticType for #name {
#[inline]
fn static_type() -> #crate_ident::Type {
Self::register_flags()
Expand Down
Loading

0 comments on commit eaff2e9

Please sign in to comment.