Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. pub struct RoomPosition(i32); // Doesnt matter for now
  2.  
  3. impl RoomPosition {
  4. pub fn find_in_range<T: FindConstant>(&self, _ty: T, _range: u32) -> Vec<T::Item> {
  5. vec![]
  6. }
  7. }
  8.  
  9. pub trait FindConstant {
  10. type Item: FromExpectedType<i32>;
  11. }
  12.  
  13. #[derive(Debug)]
  14. pub struct ConversionError;
  15.  
  16. pub trait FromExpectedType<T>: Sized {
  17. fn from_expected_type(v: T) -> Result<Self, ConversionError>;
  18. }
  19.  
  20. pub fn count_in_range<T, F>(pos: RoomPosition, find_type: T, range: u32, filter: F) -> u32
  21. where
  22. T : FindConstant,
  23. for<'r> F : FnMut(&'r T::Item) -> bool
  24. {
  25. pos
  26. .find_in_range(find_type, range)
  27. .into_iter()
  28. .filter(filter)
  29. .count() as u32
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement