Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/test-utils/src/minicore.rs')
| -rw-r--r-- | crates/test-utils/src/minicore.rs | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs index 4a2346193b..fd06736a25 100644 --- a/crates/test-utils/src/minicore.rs +++ b/crates/test-utils/src/minicore.rs @@ -32,7 +32,7 @@ //! error: fmt //! fmt: option, result, transmute, coerce_unsized, copy, clone, derive //! fn: tuple -//! from: sized +//! from: sized, result //! future: pin //! coroutine: pin //! dispatch_from_dyn: unsize, pin @@ -332,6 +332,25 @@ pub mod convert { t } } + + pub trait TryFrom<T>: Sized { + type Error; + fn try_from(value: T) -> Result<Self, Self::Error>; + } + pub trait TryInto<T>: Sized { + type Error; + fn try_into(self) -> Result<T, Self::Error>; + } + + impl<T, U> TryInto<U> for T + where + U: TryFrom<T>, + { + type Error = U::Error; + fn try_into(self) -> Result<U, U::Error> { + U::try_from(self) + } + } // endregion:from // region:as_ref @@ -1510,7 +1529,7 @@ pub mod iter { impl<T, const N: usize> IntoIterator for [T; N] { type Item = T; type IntoIter = IntoIter<T, N>; - fn into_iter(self) -> I { + fn into_iter(self) -> Self::IntoIter { IntoIter { data: self, range: IndexRange { start: 0, end: loop {} } } } } @@ -1520,6 +1539,29 @@ pub mod iter { loop {} } } + pub struct Iter<'a, T> { + slice: &'a [T], + } + impl<'a, T> IntoIterator for &'a [T; N] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + loop {} + } + } + impl<'a, T> IntoIterator for &'a [T] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + loop {} + } + } + impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + fn next(&mut self) -> Option<T> { + loop {} + } + } } pub use self::collect::IntoIterator; } @@ -1532,6 +1574,15 @@ pub mod str { pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { "" } + pub trait FromStr: Sized { + type Err; + fn from_str(s: &str) -> Result<Self, Self::Err>; + } + impl str { + pub fn parse<F: FromStr>(&self) -> Result<F, F::Err> { + FromStr::from_str(self) + } + } } // endregion:str @@ -1791,7 +1842,7 @@ pub mod prelude { cmp::{Eq, PartialEq}, // :eq cmp::{Ord, PartialOrd}, // :ord convert::AsRef, // :as_ref - convert::{From, Into}, // :from + convert::{From, Into, TryFrom, TryInto}, // :from default::Default, // :default iter::{IntoIterator, Iterator}, // :iterator macros::builtin::{derive, derive_const}, // :derive @@ -1806,6 +1857,7 @@ pub mod prelude { option::Option::{self, None, Some}, // :option panic, // :panic result::Result::{self, Err, Ok}, // :result + str::FromStr, // :str }; } |