//! Provider of [`UseExt`].

use crate::S;

/// Extention trait for method `r#use`.
pub trait UseExt<T> {
    /// Returns self wrapped by [`S`].
    ///
    /// ```
    /// use subject::prelude::*;
    /// use subject::UseExt;
    /// use subject::exts::UpgetExt;
    ///
    /// let arr = [1, 3, 4, 2, 5];
    /// let sorted = arr.r#use().upget(|x| x.sort());
    /// assert_eq!(sorted, [1, 2, 3, 4, 5]);
    /// ```
    fn r#use(self) -> S<Self>;
}

impl<T> UseExt<T> for T
where
    T: Sized,
{
    #[inline]
    fn r#use(self) -> S<Self> {
        S(self)
    }
}
