Skip to content
Merged
Changes from 3 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
29 changes: 29 additions & 0 deletions bounded-collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,35 @@
fn get() -> T;
}

/// Converts [`Get<I>`] to [`Get<R>`] using [`Into`].
///
/// Acts as a type-safe bridge between `Get` implementations where `I: Into<R>`.
///
/// - `Inner`: The [`Get<I>`] implementation
/// - `I`: Source type to convert from
/// - `R`: Target type to convert into
///
/// # Example
/// ```
/// struct MyGetter;
/// impl Get<u16> for MyGetter { fn get() -> u16 { 42 } }

Check failure on line 59 in bounded-collections/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Windows

cannot find trait `Get` in this scope

Check failure on line 59 in bounded-collections/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macOS-latest)

cannot find trait `Get` in this scope
/// assert_eq!(GetInto::<MyGetter, u16, u32>::get(), 42u32);

Check failure on line 60 in bounded-collections/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Windows

failed to resolve: use of undeclared type `GetInto`

Check failure on line 60 in bounded-collections/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macOS-latest)

failed to resolve: use of undeclared type `GetInto`
/// ```
pub struct GetInto<Inner, I, R>(core::marker::PhantomData<(Inner, I, R)>);

impl<Inner, I, R> Get<R> for GetInto<Inner, I, R>
where
Inner: Get<I>,
I: Into<R>,
{
/// Returns the converted value by:
/// 1. Getting the inner value of type `I`
/// 2. Converting it to type `R` using [`Into`]
fn get() -> R {
Inner::get().into()
}
}

impl<T: Default> Get<T> for () {
fn get() -> T {
T::default()
Expand Down
Loading