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

Fixed smallvec implementations to process elements inside. #82

Merged
merged 1 commit into from
Aug 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
36 changes: 25 additions & 11 deletions bounded-static/src/lib.rs
Original file line number Diff line number Diff line change
@@ -823,29 +823,33 @@ impl IntoBoundedStatic for smol_str::SmolStr {

/// [`ToBoundedStatic`] impl for `smallvec::SmallVec`.
#[cfg(feature = "smallvec")]
impl<A> ToBoundedStatic for smallvec::SmallVec<A>
impl<A, T> ToBoundedStatic for smallvec::SmallVec<A>
where
A: smallvec::Array + 'static,
A::Item: Clone,
A: smallvec::Array<Item = T> + ToBoundedStatic,
T: ToBoundedStatic,
<A as ToBoundedStatic>::Static: smallvec::Array<Item = T::Static>,
{
type Static = Self;
type Static = smallvec::SmallVec<A::Static>;

fn to_static(&self) -> Self::Static {
self.clone()
self.iter().map(ToBoundedStatic::to_static).collect()
}
}

/// No-op [`IntoBoundedStatic`] impl for `smallvec::SmallVec`.
/// [`IntoBoundedStatic`] impl for `smallvec::SmallVec`.
#[cfg(feature = "smallvec")]
impl<A> IntoBoundedStatic for smallvec::SmallVec<A>
impl<A, T> IntoBoundedStatic for smallvec::SmallVec<A>
where
A: smallvec::Array + 'static,
A::Item: Clone,
A: smallvec::Array<Item = T> + IntoBoundedStatic,
T: IntoBoundedStatic,
<A as IntoBoundedStatic>::Static: smallvec::Array<Item = T::Static>,
{
type Static = Self;
type Static = smallvec::SmallVec<A::Static>;

fn into_static(self) -> Self::Static {
self
self.into_iter()
.map(IntoBoundedStatic::into_static)
.collect()
}
}

@@ -1604,6 +1608,16 @@ mod smallvec_tests {
ensure_static(small_vec.to_static());
ensure_static(small_vec.into_static());
}

#[test]
fn test_smallvec3() {
let x = String::from("foo");
let y = String::from("bar");
let buf = [Cow::Borrowed(x.as_str()), Cow::Borrowed(y.as_str())];
let small_vec: smallvec::SmallVec<_> = smallvec::SmallVec::from_buf(buf);
ensure_static(small_vec.to_static());
ensure_static(small_vec.into_static());
}
}

#[cfg(feature = "smartstring")]