<commit_before>// Copyright 2018, The Gtk-rs Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use glib_sys;
use std::ffi::CStr;
use std::fmt;
use translate::*;

#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[repr(C)]
pub struct Quark(glib_sys::GQuark);

impl Quark {
    pub fn from_string(s: &str) -> Quark {
        unsafe { from_glib(glib_sys::g_quark_from_static_string(s.to_glib_full())) }
    }

    #[allow(clippy::trivially_copy_pass_by_ref)]
    pub fn to_string(&self) -> &'static str {
        unsafe {
            CStr::from_ptr(glib_sys::g_quark_to_string(self.to_glib()))
                .to_str()
                .unwrap()
        }
    }

    pub fn try_string(s: &str) -> Option<Quark> {
        unsafe {
            match glib_sys::g_quark_try_string(s.to_glib_none().0) {
                0 => None,
                x => Some(from_glib(x)),
            }
        }
    }
}

impl fmt::Debug for Quark {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        f.write_str(Quark::to_string(self))
    }
}

#[doc(hidden)]
impl FromGlib<glib_sys::GQuark> for Quark {
    fn from_glib(value: glib_sys::GQuark) -> Self {
        Quark(value)
    }
}

#[doc(hidden)]
impl ToGlib for Quark {
    type GlibType = glib_sys::GQuark;

    fn to_glib(&self) -> glib_sys::GQuark {
        self.0
    }
}
<commit_msg>Don't pass an owned string to g_quark_from_static_string()<commit_after>// Copyright 2018, The Gtk-rs Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use glib_sys;
use std::ffi::CStr;
use std::fmt;
use translate::*;

#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[repr(C)]
pub struct Quark(glib_sys::GQuark);

impl Quark {
    pub fn from_string(s: &str) -> Quark {
        unsafe { from_glib(glib_sys::g_quark_from_string(s.to_glib_none().0)) }
    }

    #[allow(clippy::trivially_copy_pass_by_ref)]
    pub fn to_string(&self) -> &'static str {
        unsafe {
            CStr::from_ptr(glib_sys::g_quark_to_string(self.to_glib()))
                .to_str()
                .unwrap()
        }
    }

    pub fn try_string(s: &str) -> Option<Quark> {
        unsafe {
            match glib_sys::g_quark_try_string(s.to_glib_none().0) {
                0 => None,
                x => Some(from_glib(x)),
            }
        }
    }
}

impl fmt::Debug for Quark {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        f.write_str(Quark::to_string(self))
    }
}

#[doc(hidden)]
impl FromGlib<glib_sys::GQuark> for Quark {
    fn from_glib(value: glib_sys::GQuark) -> Self {
        Quark(value)
    }
}

#[doc(hidden)]
impl ToGlib for Quark {
    type GlibType = glib_sys::GQuark;

    fn to_glib(&self) -> glib_sys::GQuark {
        self.0
    }
}

{'fraction_non_alphanumeric': 0.14473684210526316, 'fraction_numerical': 0.004934210526315789, 'mean_word_length': 2.672705314009662, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '172348', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1116, 'n_words': 232}