node_info.rs 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #[derive(Clone)]
  2. pub struct NodeInfoView {
  3. pub index: usize,
  4. pub infos: Vec<NodeInfo>,
  5. }
  6. impl NodeInfoView {
  7. pub fn new(infos: Vec<NodeInfo>) -> NodeInfoView {
  8. let index = 0;
  9. NodeInfoView { index, infos }
  10. }
  11. pub fn next(&mut self) {
  12. self.index = (self.index + 1) % self.infos.len();
  13. }
  14. pub fn previous(&mut self) {
  15. if self.index > 0 {
  16. self.index -= 1;
  17. } else {
  18. self.index = self.infos.len() - 1;
  19. }
  20. }
  21. }
  22. #[derive(Clone)]
  23. pub struct NodeInfo {
  24. pub id: String,
  25. pub connections: usize,
  26. pub is_active: bool,
  27. pub last_message: String,
  28. }
  29. impl NodeInfo {
  30. pub fn new() -> NodeInfo {
  31. let connections = 0;
  32. let is_active = false;
  33. NodeInfo { id: String::new(), connections, is_active, last_message: String::new() }
  34. }
  35. }