Browse Source

Rename section_interface::SectionId

To SecId
master
Alex Mikhalev 4 years ago
parent
commit
7cb956c2bd
  1. 4
      src/model/section.rs
  2. 18
      src/section_interface.rs

4
src/model/section.rs

@ -1,4 +1,4 @@
use crate::section_interface::SectionId; use crate::section_interface::SecId;
use rusqlite::{Error as SqlError, Row as SqlRow, ToSql}; use rusqlite::{Error as SqlError, Row as SqlRow, ToSql};
use std::sync::Arc; use std::sync::Arc;
@ -6,7 +6,7 @@ use std::sync::Arc;
pub struct Section { pub struct Section {
pub id: u32, pub id: u32,
pub name: String, pub name: String,
pub interface_id: SectionId, pub interface_id: SecId,
} }
impl Section { impl Section {

18
src/section_interface.rs

@ -2,12 +2,12 @@ use std::iter::repeat_with;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use tracing::debug; use tracing::debug;
pub type SectionId = u32; pub type SecId = u32;
pub trait SectionInterface: Send { pub trait SectionInterface: Send {
fn num_sections(&self) -> SectionId; fn num_sections(&self) -> SecId;
fn set_section_state(&self, id: SectionId, running: bool); fn set_section_state(&self, id: SecId, running: bool);
fn get_section_state(&self, id: SectionId) -> bool; fn get_section_state(&self, id: SecId) -> bool;
} }
pub struct MockSectionInterface { pub struct MockSectionInterface {
@ -16,7 +16,7 @@ pub struct MockSectionInterface {
impl MockSectionInterface { impl MockSectionInterface {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new(num_sections: SectionId) -> Self { pub fn new(num_sections: SecId) -> Self {
Self { Self {
states: repeat_with(|| AtomicBool::new(false)) states: repeat_with(|| AtomicBool::new(false))
.take(num_sections as usize) .take(num_sections as usize)
@ -26,14 +26,14 @@ impl MockSectionInterface {
} }
impl SectionInterface for MockSectionInterface { impl SectionInterface for MockSectionInterface {
fn num_sections(&self) -> SectionId { fn num_sections(&self) -> SecId {
self.states.len() as SectionId self.states.len() as SecId
} }
fn set_section_state(&self, id: SectionId, running: bool) { fn set_section_state(&self, id: SecId, running: bool) {
debug!(id, running, "setting section"); debug!(id, running, "setting section");
self.states[id as usize].store(running, Ordering::SeqCst); self.states[id as usize].store(running, Ordering::SeqCst);
} }
fn get_section_state(&self, id: SectionId) -> bool { fn get_section_state(&self, id: SecId) -> bool {
self.states[id as usize].load(Ordering::SeqCst) self.states[id as usize].load(Ordering::SeqCst)
} }
} }

Loading…
Cancel
Save