Skip to content

Commit

Permalink
add missing from_static for string
Browse files Browse the repository at this point in the history
  • Loading branch information
polazarus committed Aug 10, 2023
1 parent 18d2c5c commit 8cd1727
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,13 @@ where
}
}

impl<B: Backend> HipByt<'static, B> {
impl<B> HipByt<'static, B>
where
B: Backend,
{
/// Creates a new `HipByt` from a static slice without copying the slice.
///
/// Handy shortcut to make a `HipByt<'static, _>`.
/// Handy shortcut to make a `HipByt<'static, _>` out of a `&'static [u8]`.
///
/// # Examples
///
Expand All @@ -442,6 +445,7 @@ impl<B: Backend> HipByt<'static, B> {
/// let b = HipByt::from_static(b"hello\0");
/// assert_eq!(b.len(), 6);
/// ```
#[inline]
#[must_use]
pub const fn from_static(bytes: &'static [u8]) -> Self {
Self::borrowed(bytes)
Expand Down
24 changes: 24 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,30 @@ where
}
}

impl<B> HipStr<'static, B>
where
B: Backend,
{
/// Creates a new `HipStr` from a static string slice without copying the slice.
///
/// Handy shortcut to make a `HipStr<'static, _>` out of a `&'static str`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # use hipstr::HipStr;
/// let s = HipStr::from_static("hello");
/// assert_eq!(s.len(), 5);
/// ```
#[inline]
#[must_use]
pub const fn from_static(value: &'static str) -> Self {
Self::borrowed(value)
}
}

// Manual implementation needed to remove trait bound on B::RawPointer.
impl<'borrow, B> Clone for HipStr<'borrow, B>
where
Expand Down

0 comments on commit 8cd1727

Please sign in to comment.