Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Type {
- Network,
- Temperature,
- Load,
- Time,
- Fan,
- Usage
- }
- // A sensor has a specific "type" and an array of "Data"
- struct Sensor {
- data: Vec<Data>,
- sensor_type: Type
- }
- // Data represents the raw value that a sensor can use. I.e. a Sensor can have multiple data inputs.
- struct Data {
- value: i64,
- path: PathBuf,
- }
- // Different sensors are later stored in an array of trait objects
- trait Readable {
- fn format(&self) -> &str;
- }
- // Each sensor type has a unique method to format it's data.
- impl Readable for Sensor {
- fn format(&self) ->&str {
- match self.sensor_type {
- Type::Network => "Network",
- Type::Temperature => "Temp",
- Type::Load => "Load",
- Type::Time => "Time",
- Type::Fan => "Fan",
- Type::Usage => "Usage"
- }
- }
- }
- // "read_data" reads the raw value from the "path" variable specified in the Data struct.
- impl Data {
- fn read_data(&mut self) {
- if let Ok(val) = fs::read(&self.path) {
- self.raw = val;
- println!("{:?}",self.raw);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement