diff --git a/rustfmt.toml b/rustfmt.toml index f5f3f01675..a74b3f84f8 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -54,5 +54,5 @@ use_field_init_shorthand = true use_small_heuristics = "Default" use_try_shorthand = true version = "Two" -where_single_line = true +where_single_line = false wrap_comments = true diff --git a/src/types.rs b/src/types.rs index 743837598c..95d63bf486 100644 --- a/src/types.rs +++ b/src/types.rs @@ -479,7 +479,9 @@ impl Janet { /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn unwrap_or_default(self) -> T - where T: TryFrom + Default { + where + T: TryFrom + Default, + { T::try_from(self).unwrap_or_default() } @@ -1804,7 +1806,10 @@ pub trait JanetArgs { /// todo!() /// } /// ``` - fn try_get>(&self, index: usize) -> Result { + fn try_get(&self, index: usize) -> Result + where + T: TryFrom, + { T::try_from(self.get_value(index).unwrap_or(Janet::nil())) } @@ -1826,7 +1831,10 @@ pub trait JanetArgs { /// todo!() /// } /// ``` - fn get_or>(&self, index: usize, default: T) -> T { + fn get_or(&self, index: usize, default: T) -> T + where + T: TryFrom, + { self.get_value(index) .and_then(|val| T::try_from(val).ok()) .unwrap_or(default) @@ -1854,7 +1862,10 @@ pub trait JanetArgs { /// todo!() /// } /// ``` - fn get_opt + JanetTypeName>(&self, index: usize, default: T) -> T { + fn get_opt(&self, index: usize, default: T) -> T + where + T: TryFrom + JanetTypeName, + { let val = self.get_value(index).unwrap_or_else(Janet::nil); if val.is_nil() { return default; @@ -1890,7 +1901,10 @@ pub trait JanetArgs { /// todo!() /// } /// ``` - fn get_or_panic + JanetTypeName>(&self, index: usize) -> T { + fn get_or_panic(&self, index: usize) -> T + where + T: TryFrom + JanetTypeName, + { match self.get_value(index) { Some(val) => T::try_from(val).unwrap_or_else(|_| { crate::jpanic!( diff --git a/src/types/abstract.rs b/src/types/abstract.rs index 0cd8c10ba1..50802897e7 100644 --- a/src/types/abstract.rs +++ b/src/types/abstract.rs @@ -398,7 +398,8 @@ impl IsJanetAbstract for u64 { } impl IsJanetAbstract for ManuallyDrop -where A: IsJanetAbstract +where + A: IsJanetAbstract, { type Get = ManuallyDrop; diff --git a/src/types/array.rs b/src/types/array.rs index d8dde323e7..4805df5aa8 100644 --- a/src/types/array.rs +++ b/src/types/array.rs @@ -457,7 +457,9 @@ impl<'data> JanetArray<'data> { /// assert_eq!(array.pop_if(pred), None); /// ``` pub fn pop_if(&mut self, f: F) -> Option - where F: FnOnce(&mut Janet) -> bool { + where + F: FnOnce(&mut Janet) -> bool, + { let last = self.last_mut()?; if f(last) { self.pop() } else { None } } @@ -568,7 +570,9 @@ impl<'data> JanetArray<'data> { #[inline] #[must_use] pub fn get_range(&self, range: R) -> Option<&[Janet]> - where R: RangeBounds { + where + R: RangeBounds, + { into_range(self.len(), (range.start_bound(), range.end_bound())) .and_then(|range| self.get_r(range)) } @@ -576,7 +580,9 @@ impl<'data> JanetArray<'data> { #[inline] #[must_use] pub fn get_range_mut(&mut self, range: R) -> Option<&mut [Janet]> - where R: RangeBounds { + where + R: RangeBounds, + { into_range(self.len(), (range.start_bound(), range.end_bound())) .and_then(|range| self.get_r_mut(range)) } @@ -584,7 +590,9 @@ impl<'data> JanetArray<'data> { /// # Safety #[inline] pub unsafe fn get_range_unchecked(&self, range: R) -> &[Janet] - where R: RangeBounds { + where + R: RangeBounds, + { self.get_r_unchecked(into_range_unchecked( self.len(), (range.start_bound(), range.end_bound()), @@ -594,7 +602,9 @@ impl<'data> JanetArray<'data> { /// # Safety #[inline] pub unsafe fn get_range_unchecked_mut(&mut self, range: R) -> &mut [Janet] - where R: RangeBounds { + where + R: RangeBounds, + { self.get_r_unchecked_mut(into_range_unchecked( self.len(), (range.start_bound(), range.end_bound()), @@ -731,7 +741,9 @@ impl<'data> JanetArray<'data> { /// assert_eq!(vec, [2, 3, 5]); /// ``` pub fn retain(&mut self, mut f: F) - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.retain_mut(|elem| f(elem)); } @@ -766,7 +778,9 @@ impl<'data> JanetArray<'data> { /// assert_deep_eq!(array, array![2, 3, 4]); /// ``` pub fn retain_mut(&mut self, mut f: F) - where F: FnMut(&mut Janet) -> bool { + where + F: FnMut(&mut Janet) -> bool, + { // Array: [Kept, Kept, Hole, Hole, Hole, Hole, Unchecked, Unchecked] // |<- processed len ->| ^- next to check // |<- deleted cnt ->| @@ -806,7 +820,9 @@ impl<'data> JanetArray<'data> { fn process_loop( original_len: usize, f: &mut F, g: &mut BackshiftOnDrop<'_, '_>, - ) where F: FnMut(&mut Janet) -> bool { + ) where + F: FnMut(&mut Janet) -> bool, + { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. let cur = unsafe { &mut *g.v.as_mut_ptr().add(g.processed_len) }; @@ -1499,7 +1515,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result - where F: FnMut(&'a Janet) -> Ordering { + where + F: FnMut(&'a Janet) -> Ordering, + { self.as_ref().binary_search_by(f) } @@ -1577,7 +1595,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn dedup_by_key(&mut self, mut key: F) - where F: FnMut(&mut Janet) -> Janet { + where + F: FnMut(&mut Janet) -> Janet, + { self.dedup_by(|a, b| key(a) == key(b)) } @@ -1603,7 +1623,9 @@ impl<'data> JanetArray<'data> { /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn dedup_by(&mut self, mut same_bucket: F) - where F: FnMut(&mut Janet, &mut Janet) -> bool { + where + F: FnMut(&mut Janet, &mut Janet) -> bool, + { let len = self.len() as usize; if len <= 1 { return; @@ -1732,7 +1754,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn sort_by(&mut self, compare: F) - where F: FnMut(&Janet, &Janet) -> Ordering { + where + F: FnMut(&Janet, &Janet) -> Ordering, + { self.as_mut().sort_by(compare) } @@ -1858,7 +1882,9 @@ impl<'data> JanetArray<'data> { /// [pdqsort]: https://github.com/orlp/pdqsort #[inline] pub fn sort_unstable_by(&mut self, compare: F) - where F: FnMut(&Janet, &Janet) -> Ordering { + where + F: FnMut(&Janet, &Janet) -> Ordering, + { self.as_mut().sort_unstable_by(compare) } @@ -2367,7 +2393,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn split(&self, pred: F) -> Split<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().split(pred) } @@ -2392,7 +2420,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn split_mut(&mut self, pred: F) -> SplitMut<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_mut().split_mut(pred) } @@ -2437,7 +2467,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn rsplit(&self, pred: F) -> RSplit<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().rsplit(pred) } @@ -2465,7 +2497,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn rsplit_mut(&mut self, pred: F) -> RSplitMut<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_mut().rsplit_mut(pred) } @@ -2496,7 +2530,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn splitn(&self, n: usize, pred: F) -> SplitN<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().splitn(n, pred) } @@ -2525,7 +2561,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn splitn_mut(&mut self, n: usize, pred: F) -> SplitNMut<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_mut().splitn_mut(n, pred) } @@ -2557,7 +2595,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn rsplitn(&self, n: usize, pred: F) -> RSplitN<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().rsplitn(n, pred) } @@ -2587,7 +2627,9 @@ impl<'data> JanetArray<'data> { /// ``` #[inline] pub fn rsplitn_mut(&mut self, n: usize, pred: F) -> RSplitNMut<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_mut().rsplitn_mut(n, pred) } @@ -2651,7 +2693,9 @@ impl<'data> JanetArray<'data> { /// assert_deep_eq!(odds, array![1, 3, 5, 9, 11, 13, 15]); /// ``` pub fn extract_if(&mut self, filter: F) -> ExtractIf<'_, 'data, F> - where F: FnMut(&mut Janet) -> bool { + where + F: FnMut(&mut Janet) -> bool, + { let old_len = self.len() as usize; ExtractIf { arr: self, @@ -3215,7 +3259,8 @@ impl FusedIterator for IntoIter<'_> {} #[derive(Debug)] #[must_use = "iterators are lazy and do nothing unless consumed"] pub struct ExtractIf<'a, 'data, F> -where F: FnMut(&mut Janet) -> bool +where + F: FnMut(&mut Janet) -> bool, { arr: &'a mut JanetArray<'data>, idx: usize, @@ -3225,7 +3270,8 @@ where F: FnMut(&mut Janet) -> bool } impl Iterator for ExtractIf<'_, '_, F> -where F: FnMut(&mut Janet) -> bool +where + F: FnMut(&mut Janet) -> bool, { type Item = Janet; @@ -3261,7 +3307,8 @@ where F: FnMut(&mut Janet) -> bool } impl Drop for ExtractIf<'_, '_, F> -where F: FnMut(&mut Janet) -> bool +where + F: FnMut(&mut Janet) -> bool, { fn drop(&mut self) { unsafe { diff --git a/src/types/buffer.rs b/src/types/buffer.rs index 20ee028d6e..6e6a87322e 100644 --- a/src/types/buffer.rs +++ b/src/types/buffer.rs @@ -1599,7 +1599,9 @@ impl JanetBuffer<'_> { /// ``` #[inline] pub fn rfind_iter<'a, 'b, B>(&'a self, needle: &'b B) -> FindReverse<'a, 'b> - where B: ?Sized + AsRef<[u8]> { + where + B: ?Sized + AsRef<[u8]>, + { self.as_bytes().rfind_iter(needle) } @@ -1748,7 +1750,9 @@ impl JanetBuffer<'_> { /// ``` #[inline] pub fn fields_with(&self, f: F) -> FieldsWith - where F: FnMut(char) -> bool { + where + F: FnMut(char) -> bool, + { self.as_bytes().fields_with(f) } @@ -2119,7 +2123,9 @@ impl JanetBuffer<'_> { /// [`fields`](#method.fields) instead. #[inline] pub fn split<'a, 'b, S>(&'a self, splitter: &'b S) -> Split<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().split_str(splitter) } @@ -2257,7 +2263,9 @@ impl JanetBuffer<'_> { /// It does *not* give you `["a", "b", "c"]`. #[inline] pub fn rsplit<'a, 'b, S>(&'a self, splitter: &'b S) -> SplitReverse<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().rsplit_str(splitter) } @@ -2306,7 +2314,9 @@ impl JanetBuffer<'_> { /// ``` #[inline] pub fn splitn<'a, 'b, S>(&'a self, limit: usize, splitter: &'b S) -> SplitN<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().splitn_str(limit, splitter) } @@ -2355,7 +2365,9 @@ impl JanetBuffer<'_> { /// ``` #[inline] pub fn rsplitn<'a, 'b, S>(&'a self, limit: usize, splitter: &'b S) -> SplitNReverse<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().rsplitn_str(limit, splitter) } diff --git a/src/types/fiber.rs b/src/types/fiber.rs index 1725e47c3b..fdd40c4e80 100644 --- a/src/types/fiber.rs +++ b/src/types/fiber.rs @@ -234,7 +234,9 @@ impl<'data> JanetFiber<'data> { /// [`exec`]: #method.exec #[inline] pub fn exec_with<'a, F>(&'a mut self, f: F) -> Exec<'a, 'data> - where F: FnOnce() -> Janet { + where + F: FnOnce() -> Janet, + { Exec { fiber: self, input: f(), diff --git a/src/types/string.rs b/src/types/string.rs index 381a09ce0a..6653509019 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -1297,7 +1297,9 @@ impl<'data> JanetString<'data> { /// ``` #[inline] pub fn find_iter<'a, 'b, B>(&'a self, needle: &'b B) -> Find<'a, 'b> - where B: ?Sized + AsRef<[u8]> { + where + B: ?Sized + AsRef<[u8]>, + { self.as_bytes().find_iter(needle) } @@ -1342,7 +1344,9 @@ impl<'data> JanetString<'data> { /// ``` #[inline] pub fn rfind_iter<'a, 'b, B>(&'a self, needle: &'b B) -> FindReverse<'a, 'b> - where B: ?Sized + AsRef<[u8]> { + where + B: ?Sized + AsRef<[u8]>, + { self.as_bytes().rfind_iter(needle) } @@ -1491,7 +1495,9 @@ impl<'data> JanetString<'data> { /// ``` #[inline] pub fn fields_with(&self, f: F) -> FieldsWith - where F: FnMut(char) -> bool { + where + F: FnMut(char) -> bool, + { self.as_bytes().fields_with(f) } @@ -1841,7 +1847,9 @@ impl<'data> JanetString<'data> { /// [`fields`](#method.fields) instead. #[inline] pub fn split<'a, 'b, S>(&'a self, splitter: &'b S) -> Split<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().split_str(splitter) } @@ -1979,7 +1987,9 @@ impl<'data> JanetString<'data> { /// It does *not* give you `["a", "b", "c"]`. #[inline] pub fn rsplit<'a, 'b, S>(&'a self, splitter: &'b S) -> SplitReverse<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().rsplit_str(splitter) } @@ -2028,7 +2038,9 @@ impl<'data> JanetString<'data> { /// ``` #[inline] pub fn splitn<'a, 'b, S>(&'a self, limit: usize, splitter: &'b S) -> SplitN<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().splitn_str(limit, splitter) } @@ -2077,7 +2089,9 @@ impl<'data> JanetString<'data> { /// ``` #[inline] pub fn rsplitn<'a, 'b, S>(&'a self, limit: usize, splitter: &'b S) -> SplitNReverse<'a, 'b> - where S: ?Sized + AsRef<[u8]> { + where + S: ?Sized + AsRef<[u8]>, + { self.as_bytes().rsplitn_str(limit, splitter) } diff --git a/src/types/table.rs b/src/types/table.rs index 96dd27f66e..24557a35f0 100644 --- a/src/types/table.rs +++ b/src/types/table.rs @@ -1432,7 +1432,9 @@ impl<'a, 'data> Entry<'a, 'data> { #[inline] #[must_use] pub fn and_modify(self, f: F) -> Self - where F: FnOnce(&mut Janet) { + where + F: FnOnce(&mut Janet), + { match self { Self::Occupied(mut entry) => { f(entry.get_mut()); @@ -1524,7 +1526,9 @@ impl<'a, 'data> Entry<'a, 'data> { /// ``` #[inline] pub fn or_insert_with(self, default: F) -> &'a mut Janet - where F: FnOnce() -> Janet { + where + F: FnOnce() -> Janet, + { match self { Self::Occupied(entry) => entry.into_mut(), Self::Vacant(entry) => entry.insert(default()), @@ -1549,7 +1553,9 @@ impl<'a, 'data> Entry<'a, 'data> { /// ``` #[inline] pub fn or_insert_with_key(self, default: F) -> &'a mut Janet - where F: FnOnce(&Janet) -> Janet { + where + F: FnOnce(&Janet) -> Janet, + { match self { Self::Occupied(entry) => entry.into_mut(), Self::Vacant(entry) => { diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 9440513325..9063bdd0d5 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -587,7 +587,9 @@ impl<'data> JanetTuple<'data> { /// ``` #[inline] pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result - where F: FnMut(&'a Janet) -> Ordering { + where + F: FnMut(&'a Janet) -> Ordering, + { self.as_ref().binary_search_by(f) } @@ -876,7 +878,9 @@ impl<'data> JanetTuple<'data> { /// ``` #[inline] pub fn split(&self, pred: F) -> Split<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().split(pred) } @@ -921,7 +925,9 @@ impl<'data> JanetTuple<'data> { /// ``` #[inline] pub fn rsplit(&self, pred: F) -> RSplit<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().rsplit(pred) } @@ -952,7 +958,9 @@ impl<'data> JanetTuple<'data> { /// ``` #[inline] pub fn splitn(&self, n: usize, pred: F) -> SplitN<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().splitn(n, pred) } @@ -984,7 +992,9 @@ impl<'data> JanetTuple<'data> { /// ``` #[inline] pub fn rsplitn(&self, n: usize, pred: F) -> RSplitN<'_, F> - where F: FnMut(&Janet) -> bool { + where + F: FnMut(&Janet) -> bool, + { self.as_ref().rsplitn(n, pred) }