Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
glib: add doc alias for manual types
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Dec 20, 2020
1 parent 6bb5a5a commit 4b41caa
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 0 deletions.
2 changes: 2 additions & 0 deletions glib/src/bridged_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl GlibLogger {
}
}

#[doc(alias = "g_log")]
fn write_log(domain: Option<&str>, level: rs_log::Level, message: &str) {
unsafe {
crate::ffi::g_log(
Expand All @@ -118,6 +119,7 @@ impl GlibLogger {

#[cfg(any(feature = "v2_56", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))]
#[doc(alias = "g_log_structured_standard")]
fn write_log_structured(
domain: Option<&str>,
level: rs_log::Level,
Expand Down
10 changes: 10 additions & 0 deletions glib/src/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ wrapper! {
}

impl ByteArray {
#[doc(alias = "g_byte_array_new")]
pub fn new() -> ByteArray {
unsafe { from_glib_full(ffi::g_byte_array_new()) }
}

#[doc(alias = "g_byte_array_sized_new")]
pub fn with_capacity(size: usize) -> ByteArray {
unsafe { from_glib_full(ffi::g_byte_array_sized_new(size as u32)) }
}

#[doc(alias = "g_byte_array_free_to_bytes")]
pub fn into_gbytes(self) -> Bytes {
unsafe {
let s = mem::ManuallyDrop::new(self);
Expand All @@ -52,6 +55,7 @@ impl ByteArray {
}
}

#[doc(alias = "g_byte_array_append")]
pub fn append<T: ?Sized + AsRef<[u8]>>(&self, data: &T) -> &Self {
let bytes = data.as_ref();
unsafe {
Expand All @@ -64,6 +68,7 @@ impl ByteArray {
self
}

#[doc(alias = "g_byte_array_prepend")]
pub fn prepend<T: ?Sized + AsRef<[u8]>>(&self, data: &T) -> &Self {
let bytes = data.as_ref();
unsafe {
Expand All @@ -76,28 +81,33 @@ impl ByteArray {
self
}

#[doc(alias = "g_byte_array_remove_index")]
pub fn remove_index(&self, index: usize) {
unsafe {
ffi::g_byte_array_remove_index(self.to_glib_none().0, index as u32);
}
}

#[doc(alias = "g_byte_array_remove_index_fast")]
pub fn remove_index_fast(&self, index: usize) {
unsafe {
ffi::g_byte_array_remove_index_fast(self.to_glib_none().0, index as u32);
}
}

#[doc(alias = "g_byte_array_remove_range")]
pub fn remove_range(&self, index: usize, length: usize) {
unsafe {
ffi::g_byte_array_remove_range(self.to_glib_none().0, index as u32, length as u32);
}
}

#[doc(alias = "g_byte_array_set_size")]
pub unsafe fn set_size(&self, size: usize) {
ffi::g_byte_array_set_size(self.to_glib_none().0, size as u32);
}

#[doc(alias = "g_byte_array_sort_with_data")]
pub fn sort<F: FnMut(&u8, &u8) -> Ordering>(&self, compare_func: F) {
unsafe extern "C" fn compare_func_trampoline(
a: ffi::gconstpointer,
Expand Down
2 changes: 2 additions & 0 deletions glib/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ wrapper! {

impl Bytes {
/// Copies `data` into a new shared slice.
#[doc(alias = "g_bytes_new")]
fn new<T: AsRef<[u8]>>(data: T) -> Bytes {
let data = data.as_ref();
unsafe { from_glib_full(ffi::g_bytes_new(data.as_ptr() as *const _, data.len())) }
}

/// Creates a view into static `data` without copying.
#[doc(alias = "g_bytes_new_static")]
pub fn from_static(data: &'static [u8]) -> Bytes {
unsafe {
from_glib_full(ffi::g_bytes_new_static(
Expand Down
2 changes: 2 additions & 0 deletions glib/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use libc::size_t;
use std::vec::Vec;

impl Checksum {
#[doc(alias = "g_checksum_get_digest")]
pub fn get_digest(self) -> Vec<u8> {
unsafe {
//Don't forget update when `ChecksumType` contains type bigger that Sha512.
Expand All @@ -23,6 +24,7 @@ impl Checksum {
}
}

#[doc(alias = "g_checksum_get_string")]
pub fn get_string(self) -> Option<String> {
unsafe {
from_glib_none(ffi::g_checksum_get_string(mut_override(
Expand Down
46 changes: 46 additions & 0 deletions glib/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,43 @@ unsafe impl Send for Date {}
unsafe impl Sync for Date {}

impl Date {
#[doc(alias = "g_date_new")]
pub fn new() -> Date {
unsafe { from_glib_full(ffi::g_date_new()) }
}

#[doc(alias = "g_date_new_dmy")]
pub fn new_dmy(day: DateDay, month: DateMonth, year: DateYear) -> Date {
unsafe { from_glib_full(ffi::g_date_new_dmy(day, month.to_glib(), year)) }
}

#[doc(alias = "g_date_new_julian")]
pub fn new_julian(julian_day: u32) -> Date {
unsafe { from_glib_full(ffi::g_date_new_julian(julian_day)) }
}

#[doc(alias = "g_date_add_days")]
pub fn add_days(&mut self, n_days: u32) {
unsafe {
ffi::g_date_add_days(self.to_glib_none_mut().0, n_days);
}
}

#[doc(alias = "g_date_add_months")]
pub fn add_months(&mut self, n_months: u32) {
unsafe {
ffi::g_date_add_months(self.to_glib_none_mut().0, n_months);
}
}

#[doc(alias = "g_date_add_years")]
pub fn add_years(&mut self, n_years: u32) {
unsafe {
ffi::g_date_add_years(self.to_glib_none_mut().0, n_years);
}
}

#[doc(alias = "g_date_clamp")]
pub fn clamp(&mut self, min_date: &Date, max_date: &Date) {
unsafe {
ffi::g_date_clamp(
Expand All @@ -66,106 +73,128 @@ impl Date {
}
}

#[doc(alias = "g_date_clear")]
pub fn clear(&mut self, n_dates: u32) {
unsafe {
ffi::g_date_clear(self.to_glib_none_mut().0, n_dates);
}
}

#[doc(alias = "g_date_compare")]
fn compare(&self, rhs: &Date) -> i32 {
unsafe { ffi::g_date_compare(self.to_glib_none().0, rhs.to_glib_none().0) }
}

#[doc(alias = "g_date_days_between")]
pub fn days_between(&self, date2: &Date) -> i32 {
unsafe { ffi::g_date_days_between(self.to_glib_none().0, date2.to_glib_none().0) }
}

#[doc(alias = "g_date_get_day")]
pub fn get_day(&self) -> DateDay {
unsafe { ffi::g_date_get_day(self.to_glib_none().0) }
}

#[doc(alias = "g_date_get_day_of_year")]
pub fn get_day_of_year(&self) -> u32 {
unsafe { ffi::g_date_get_day_of_year(self.to_glib_none().0) }
}

#[doc(alias = "g_date_get_iso8601_week_of_year")]
pub fn get_iso8601_week_of_year(&self) -> u32 {
unsafe { ffi::g_date_get_iso8601_week_of_year(self.to_glib_none().0) }
}

#[doc(alias = "g_date_get_julian")]
pub fn get_julian(&self) -> u32 {
unsafe { ffi::g_date_get_julian(self.to_glib_none().0) }
}

#[doc(alias = "g_date_get_monday_week_of_year")]
pub fn get_monday_week_of_year(&self) -> u32 {
unsafe { ffi::g_date_get_monday_week_of_year(self.to_glib_none().0) }
}

#[doc(alias = "g_date_get_month")]
pub fn get_month(&self) -> DateMonth {
unsafe { from_glib(ffi::g_date_get_month(self.to_glib_none().0)) }
}

#[doc(alias = "g_date_get_sunday_week_of_year")]
pub fn get_sunday_week_of_year(&self) -> u32 {
unsafe { ffi::g_date_get_sunday_week_of_year(self.to_glib_none().0) }
}

#[doc(alias = "g_date_get_weekday")]
pub fn get_weekday(&self) -> DateWeekday {
unsafe { from_glib(ffi::g_date_get_weekday(self.to_glib_none().0)) }
}

#[doc(alias = "g_date_get_year")]
pub fn get_year(&self) -> DateYear {
unsafe { ffi::g_date_get_year(self.to_glib_none().0) }
}

#[doc(alias = "g_date_is_first_of_month")]
pub fn is_first_of_month(&self) -> bool {
unsafe { from_glib(ffi::g_date_is_first_of_month(self.to_glib_none().0)) }
}

#[doc(alias = "g_date_is_last_of_month")]
pub fn is_last_of_month(&self) -> bool {
unsafe { from_glib(ffi::g_date_is_last_of_month(self.to_glib_none().0)) }
}

#[doc(alias = "g_date_order")]
pub fn order(&mut self, date2: &mut Date) {
unsafe {
ffi::g_date_order(self.to_glib_none_mut().0, date2.to_glib_none_mut().0);
}
}

#[doc(alias = "g_date_set_day")]
pub fn set_day(&mut self, day: DateDay) {
unsafe {
ffi::g_date_set_day(self.to_glib_none_mut().0, day);
}
}

#[doc(alias = "g_date_set_dmy")]
pub fn set_dmy(&mut self, day: DateDay, month: DateMonth, y: DateYear) {
unsafe {
ffi::g_date_set_dmy(self.to_glib_none_mut().0, day, month.to_glib(), y);
}
}

#[doc(alias = "g_date_set_julian")]
pub fn set_julian(&mut self, julian_date: u32) {
unsafe {
ffi::g_date_set_julian(self.to_glib_none_mut().0, julian_date);
}
}

#[doc(alias = "g_date_set_month")]
pub fn set_month(&mut self, month: DateMonth) {
unsafe {
ffi::g_date_set_month(self.to_glib_none_mut().0, month.to_glib());
}
}

#[doc(alias = "g_date_set_parse")]
pub fn set_parse(&mut self, str: &str) {
unsafe {
ffi::g_date_set_parse(self.to_glib_none_mut().0, str.to_glib_none().0);
}
}

#[doc(alias = "g_date_set_time")]
pub fn set_time(&mut self, time_: Time) {
unsafe {
ffi::g_date_set_time(self.to_glib_none_mut().0, time_);
}
}

#[doc(alias = "g_date_set_time_t")]
pub fn set_time_t(&mut self, timet: libc::c_long) {
unsafe {
ffi::g_date_set_time_t(self.to_glib_none_mut().0, timet);
Expand All @@ -176,54 +205,65 @@ impl Date {
// unsafe { TODO: call ffi::g_date_set_time_val() }
//}

#[doc(alias = "g_date_set_year")]
pub fn set_year(&mut self, year: DateYear) {
unsafe {
ffi::g_date_set_year(self.to_glib_none_mut().0, year);
}
}

#[doc(alias = "g_date_subtract_days")]
pub fn subtract_days(&mut self, n_days: u32) {
unsafe {
ffi::g_date_subtract_days(self.to_glib_none_mut().0, n_days);
}
}

#[doc(alias = "g_date_subtract_months")]
pub fn subtract_months(&mut self, n_months: u32) {
unsafe {
ffi::g_date_subtract_months(self.to_glib_none_mut().0, n_months);
}
}

#[doc(alias = "g_date_subtract_years")]
pub fn subtract_years(&mut self, n_years: u32) {
unsafe {
ffi::g_date_subtract_years(self.to_glib_none_mut().0, n_years);
}
}

//#[doc(alias="g_date_to_struct_tm")]
//pub fn to_struct_tm(&self, tm: /*Unimplemented*/Fundamental: Pointer) {
// unsafe { TODO: call ffi::g_date_to_struct_tm() }
//}

#[doc(alias = "g_date_valid")]
pub fn valid(&self) -> bool {
unsafe { from_glib(ffi::g_date_valid(self.to_glib_none().0)) }
}

#[doc(alias = "g_date_get_days_in_month")]
pub fn get_days_in_month(month: DateMonth, year: DateYear) -> u8 {
unsafe { ffi::g_date_get_days_in_month(month.to_glib(), year) }
}

#[doc(alias = "g_date_get_monday_weeks_in_year")]
pub fn get_monday_weeks_in_year(year: DateYear) -> u8 {
unsafe { ffi::g_date_get_monday_weeks_in_year(year) }
}

#[doc(alias = "g_date_get_sunday_weeks_in_year")]
pub fn get_sunday_weeks_in_year(year: DateYear) -> u8 {
unsafe { ffi::g_date_get_sunday_weeks_in_year(year) }
}

#[doc(alias = "g_date_is_leap_year")]
pub fn is_leap_year(year: DateYear) -> bool {
unsafe { from_glib(ffi::g_date_is_leap_year(year)) }
}

#[doc(alias = "g_date_strftime")]
pub fn strftime(s: &str, format: &str, date: &Date) -> usize {
let slen = s.len() as usize;
unsafe {
Expand All @@ -236,26 +276,32 @@ impl Date {
}
}

#[doc(alias = "g_date_valid_day")]
pub fn valid_day(day: DateDay) -> bool {
unsafe { from_glib(ffi::g_date_valid_day(day)) }
}

#[doc(alias = "g_date_valid_dmy")]
pub fn valid_dmy(day: DateDay, month: DateMonth, year: DateYear) -> bool {
unsafe { from_glib(ffi::g_date_valid_dmy(day, month.to_glib(), year)) }
}

#[doc(alias = "g_date_valid_julian")]
pub fn valid_julian(julian_date: u32) -> bool {
unsafe { from_glib(ffi::g_date_valid_julian(julian_date)) }
}

#[doc(alias = "g_date_valid_month")]
pub fn valid_month(month: DateMonth) -> bool {
unsafe { from_glib(ffi::g_date_valid_month(month.to_glib())) }
}

#[doc(alias = "g_date_valid_weekday")]
pub fn valid_weekday(weekday: DateWeekday) -> bool {
unsafe { from_glib(ffi::g_date_valid_weekday(weekday.to_glib())) }
}

#[doc(alias = "g_date_valid_year")]
pub fn valid_year(year: DateYear) -> bool {
unsafe { from_glib(ffi::g_date_valid_year(year)) }
}
Expand Down
Loading

0 comments on commit 4b41caa

Please # to comment.