[−][src]Struct bar_config::Bar
Wrapper around the bar configuration.
This is a safe wrapper around the bar configuration. It can notify consumers about any updates to the state of the configuration file.
The Bar
is the central point of interaction for any consumer. The Config
can be accessed
through an instance of Bar
using the load
method. The recv
and try_recv
methods
should be used to check for updates of any component of the configuration file.
Methods
impl Bar
[src]
pub fn load<T: Read>(config_file: T) -> Result<Self, IOError>
[src]
Load the initial bar configuration.
Loads the initial state of the bar configuration from the specified source.
The method will not launch any of the components that are specified in the configuration
file, this is done with the recv
and try_recv
methods.
Errors
If the config_file
cannot be read or its content is not valid. If the configuration is
invalid, the io::ErrorKind::InvalidData
value is returned.
Examples
use bar_config::Bar; use std::io::Cursor; let config_file = Cursor::new(String::from( "height: 30\n\ monitors:\n\ - { name: \"DVI-1\" }" )); let bar = Bar::load(config_file).unwrap(); let config = bar.lock(); assert_eq!(config.height, 30); assert_eq!(config.monitors.len(), 1); assert_eq!(config.monitors[0].name, "DVI-1");
pub fn recv(&mut self) -> ComponentID
[src]
Blocking poll for updates.
Polls the event buffer for the next event. If no event is currently queued, this will block until the next event is received.
Examples
use bar_config::Bar; use std::io::Cursor; let config_file = Cursor::new(String::from( "height: 30\n\ monitors:\n\ - { name: \"DVI-1\" }\n\ left:\n\ - { name: \"clock\" }" )); let mut bar = Bar::load(config_file).unwrap(); let component_id = bar.recv(); println!("Component {:?} was updated!", component_id);
pub fn try_recv(&mut self) -> Option<ComponentID>
[src]
Non-Blocking poll for updates.
Polls the event buffer for the next event. If no event is currently queued, this will
return None
.
Examples
use bar_config::Bar; use std::io::Cursor; let config_file = Cursor::new(String::from( "height: 30\n\ monitors:\n\ - { name: \"DVI-1\" }\n\ left:\n\ - { name: \"clock\" }" )); let mut bar = Bar::load(config_file).unwrap(); if let Some(component_id) = bar.try_recv() { println!("Component {:?} was updated!", component_id); } else { println!("No new event!"); }
pub fn lock(&self) -> MutexGuard<Config>
[src]
Lock the configuration file.
Locks the configuration file so its state can be used to render the bar. Since this creates
a MutexGuard
, no events will be received while the lock is held.
Examples
use bar_config::Bar; use std::io::Cursor; let config_file = Cursor::new(String::from( "height: 30\n\ monitors:\n\ - { name: \"DVI-1\" }" )); let mut bar = Bar::load(config_file).unwrap(); let config = bar.lock(); assert_eq!(config.height, 30); assert_eq!(config.monitors.len(), 1); assert_eq!(config.monitors[0].name, "DVI-1");
pub fn notify(&mut self, event: Event)
[src]
Send an event to all components.
Notifies all components that a new event is available. The components then have the choice to react upon the event or ignore it completely.
If a component handles the event and marks itself as dirty
as a result of the event, a
new redraw request will be queued for the recv
and try_recv
methods.
Examples
use bar_config::event::{Event, Point}; use bar_config::Bar; use std::io::Cursor; let config_file = Cursor::new(String::from( "height: 30\n\ monitors:\n\ - { name: \"DVI-1\" }" )); let mut bar = Bar::load(config_file).unwrap(); bar.notify(Event::MouseMotion(Point { x: 0, y: 0 }));
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.