Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Fix manual bindings for GString support
Browse files Browse the repository at this point in the history
  • Loading branch information
philn committed Dec 9, 2018
1 parent 54a2a65 commit c084ce4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/key_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::ptr;
use std::path;
use error::Error;
use auto::KeyFileFlags;
use gstring::GString;

use KeyFile;

Expand All @@ -37,8 +38,8 @@ impl KeyFile {
&mut full_path,
flags.to_glib(), &mut error);
if error.is_null() {
let path: String = from_glib_full(full_path);
Ok(path::PathBuf::from(path))
let path: GString = from_glib_full(full_path);
Ok(path::PathBuf::from(&path))
} else {
Err(from_glib_full(error))
}
Expand All @@ -57,15 +58,15 @@ impl KeyFile {
&mut full_path,
flags.to_glib(), &mut error);
if error.is_null() {
let path: String = from_glib_full(full_path);
Ok(path::PathBuf::from(path))
let path: GString = from_glib_full(full_path);
Ok(path::PathBuf::from(&path))
} else {
Err(from_glib_full(error))
}
}
}

pub fn to_data(&self) -> String {
pub fn to_data(&self) -> GString {
unsafe {
let ret = ffi::g_key_file_to_data(self.to_glib_none().0, ptr::null_mut(), ptr::null_mut());
from_glib_full(ret)
Expand Down
7 changes: 4 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
use error::BoolError;
use Error;
use std::ptr;
use gstring::GString;

/// Same as [`get_prgname()`].
///
Expand Down Expand Up @@ -112,7 +113,7 @@ pub fn get_current_dir() -> Option<PathBuf> {
}
}

pub fn filename_to_uri<'a, P: AsRef<Path>, Q: Into<Option<&'a str>>>(filename: P, hostname: Q) -> Result<String, Error> {
pub fn filename_to_uri<'a, P: AsRef<Path>, Q: Into<Option<&'a str>>>(filename: P, hostname: Q) -> Result<GString, Error> {
#[cfg(windows)]
use ffi::g_filename_to_uri_utf8 as g_filename_to_uri;
#[cfg(not(windows))]
Expand All @@ -127,7 +128,7 @@ pub fn filename_to_uri<'a, P: AsRef<Path>, Q: Into<Option<&'a str>>>(filename: P
}
}

pub fn filename_from_uri(uri: &str) -> Result<(std::path::PathBuf, Option<String>), Error> {
pub fn filename_from_uri(uri: &str) -> Result<(std::path::PathBuf, Option<GString>), Error> {
#[cfg(windows)]
use ffi::g_filename_from_uri_utf8 as g_filename_from_uri;
#[cfg(not(windows))]
Expand All @@ -137,7 +138,7 @@ pub fn filename_from_uri(uri: &str) -> Result<(std::path::PathBuf, Option<String
let mut hostname = ptr::null_mut();
let mut error = ptr::null_mut();
let ret = g_filename_from_uri(uri.to_glib_none().0, &mut hostname, &mut error);
if error.is_null() { Ok((from_glib_full(ret), from_glib_full(hostname))) } else { Err(from_glib_full(error)) }
if error.is_null() { Ok((from_glib_full(ret), Some(from_glib_full(hostname)))) } else { Err(from_glib_full(error)) }
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::slice;
use std::str;
use gstring::GString;

glib_wrapper! {
/// A generic immutable value capable of carrying various types.
Expand Down Expand Up @@ -113,7 +114,7 @@ impl fmt::Debug for Variant {

impl fmt::Display for Variant {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let serialized: String = unsafe {
let serialized: GString = unsafe {
from_glib_full(glib_ffi::g_variant_print(self.to_glib_none().0, false.to_glib()))
};
f.write_str(&serialized)
Expand Down

0 comments on commit c084ce4

Please sign in to comment.