8000 [pull] master from paritytech:master by pull[bot] · Pull Request #355 · zatoichi-labs/parity-common · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] master from paritytech:master #355

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

Merged
merged 1 commit into from
Apr 10, 2025
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
32 changes: 32 additions & 0 deletions bounded-collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ impl<T: Default> Get<T> for () {
}
}

/// 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
///
/// # Example
/// ```
/// use bounded_collections::Get;
/// use bounded_collections::GetInto;
///
/// struct MyGetter;
/// impl Get<u16> for MyGetter { fn get() -> u16 { 42 } }
/// let foo: u32 = GetInto::<MyGetter, u16>::get();
/// assert_eq!(foo, 42u32); // <--- infered as u32
/// ```
pub struct GetInto<Inner, I>(core::marker::PhantomData<(Inner, I)>);

impl<Inner, I, R> Get<R> for GetInto<Inner, I>
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()
}
}

/// Implement Get by returning Default for any type that implements Default.
pub struct GetDefault;
impl<T: Default> Get<T> for GetDefault {
Expand Down
Loading
0