Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strv: add join() method #989

Merged
merged 1 commit into from Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion glib/src/collections/strv.rs
Expand Up @@ -2,7 +2,7 @@

use std::{ffi::c_char, fmt, marker::PhantomData, mem, ptr};

use crate::{translate::*, GStr, GString, GStringPtr};
use crate::{translate::*, GStr, GString, GStringPtr, IntoGStr, IntoOptionalGStr};

// rustdoc-stripper-ignore-next
/// Minimum size of the `StrV` allocation.
Expand Down Expand Up @@ -851,6 +851,19 @@ impl StrV {
}
}
}

// rustdoc-stripper-ignore-next
/// Joins the strings into a longer string, with an optional separator
#[inline]
#[doc(alias = "g_strjoinv")]
pub fn join(self, separator: Option<impl IntoGStr>) -> GString {
separator.run_with_gstr(|separator| unsafe {
from_glib_full(ffi::g_strjoinv(
separator.to_glib_none().0,
self.ptr.as_ptr(),
))
})
}
}

impl FromGlibContainer<*mut c_char, *mut *mut c_char> for StrV {
Expand Down