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

Rename build to init_with #60

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/arc_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl ArcStr {
/// UTF-8 text.
///
/// This function returns `None` if memory allocation fails, see
/// [`ArcStr::build_unchecked`] for a version which calls
/// [`ArcStr::init_with_unchecked`] for a version which calls
/// [`handle_alloc_error`](alloc::alloc::handle_alloc_error).
///
/// # Safety
Expand All @@ -185,14 +185,14 @@ impl ArcStr {
/// # use arcstr::ArcStr;
/// # use core::mem::MaybeUninit;
/// let arcstr = unsafe {
/// ArcStr::try_build_unchecked(10, |s: &mut [MaybeUninit<u8>]| {
/// ArcStr::try_init_with_unchecked(10, |s: &mut [MaybeUninit<u8>]| {
/// s.fill(MaybeUninit::new(b'a'));
/// }).unwrap()
/// };
/// assert_eq!(arcstr, "aaaaaaaaaa")
/// ```
#[inline]
pub unsafe fn try_build_unchecked<F>(n: usize, initializer: F) -> Option<Self>
pub unsafe fn try_init_with_unchecked<F>(n: usize, initializer: F) -> Option<Self>
where
F: FnOnce(&mut [MaybeUninit<u8>]),
{
Expand All @@ -208,7 +208,7 @@ impl ArcStr {
///
/// This function calls
/// [`handle_alloc_error`](alloc::alloc::handle_alloc_error) if memory
/// allocation fails, see [`ArcStr::try_build_unchecked`] for a version
/// allocation fails, see [`ArcStr::try_init_with_unchecked`] for a version
/// which returns `None`
///
/// # Safety
Expand All @@ -221,14 +221,14 @@ impl ArcStr {
/// # use arcstr::ArcStr;
/// # use core::mem::MaybeUninit;
/// let arcstr = unsafe {
/// ArcStr::build_unchecked(10, |s: &mut [MaybeUninit<u8>]| {
/// ArcStr::init_with_unchecked(10, |s: &mut [MaybeUninit<u8>]| {
/// s.fill(MaybeUninit::new(b'a'));
/// })
/// };
/// assert_eq!(arcstr, "aaaaaaaaaa")
/// ```
#[inline]
pub unsafe fn build_unchecked<F>(n: usize, initializer: F) -> Self
pub unsafe fn init_with_unchecked<F>(n: usize, initializer: F) -> Self
where
F: FnOnce(&mut [MaybeUninit<u8>]),
{
Expand All @@ -246,7 +246,7 @@ impl ArcStr {
/// Note: This function is provided with a zeroed buffer, and performs UTF-8
/// validation after calling the initializer. While both of these are fast
/// operations, some high-performance use cases will be better off using
/// [`ArcStr::try_build_unchecked`] as the building block.
/// [`ArcStr::try_init_with_unchecked`] as the building block.
///
/// # Errors
/// The provided `initializer` callback must initialize the provided buffer
Expand All @@ -257,7 +257,7 @@ impl ArcStr {
/// ```
/// # use arcstr::ArcStr;
///
/// let s = ArcStr::build(5, |slice| {
/// let s = ArcStr::init_with(5, |slice| {
/// slice
/// .iter_mut()
/// .zip(b'0'..b'5')
Expand All @@ -266,7 +266,7 @@ impl ArcStr {
/// assert_eq!(s, "01234");
/// ```
#[inline]
pub fn build<F>(n: usize, initializer: F) -> Result<Self, core::str::Utf8Error>
pub fn init_with<F>(n: usize, initializer: F) -> Result<Self, core::str::Utf8Error>
where
F: FnOnce(&mut [u8]),
{
Expand Down
Loading