Skip to content

Commit

Permalink
pango: Make pango::Language::from_string() infallible
Browse files Browse the repository at this point in the history
It only ever returns `NULL` if passing `NULL`, which makes not much sense.
  • Loading branch information
sdroege authored and bilelmoussaoui committed Dec 4, 2022
1 parent f4c9889 commit c40aa68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pango/Gir.toml
Expand Up @@ -344,8 +344,12 @@ status = "generate"
const = true
[[object.function]]
name = "from_string"
# This only returns NULL when passing NULL
[[object.function.parameter]]
name = "language"
nullable = false
[object.function.return]
nullable_return_is_error = "Can't parse Language"
nullable = false

[[object]]
name = "Pango.Layout"
Expand Down
7 changes: 2 additions & 5 deletions pango/src/auto/language.rs
Expand Up @@ -59,11 +59,8 @@ impl Language {
}

#[doc(alias = "pango_language_from_string")]
pub fn from_string(language: Option<&str>) -> Result<Language, glib::BoolError> {
unsafe {
Option::<_>::from_glib_none(ffi::pango_language_from_string(language.to_glib_none().0))
.ok_or_else(|| glib::bool_error!("Can't parse Language"))
}
pub fn from_string(language: &str) -> Language {
unsafe { from_glib_none(ffi::pango_language_from_string(language.to_glib_none().0)) }
}

#[doc(alias = "pango_language_get_default")]
Expand Down
5 changes: 3 additions & 2 deletions pango/src/language.rs
Expand Up @@ -44,8 +44,9 @@ impl Language {
}

impl FromStr for Language {
type Err = glib::BoolError;
type Err = std::convert::Infallible;

fn from_str(language: &str) -> Result<Self, Self::Err> {
Self::from_string(Some(language))
Ok(Self::from_string(language))
}
}

0 comments on commit c40aa68

Please sign in to comment.