/// Load the simulator from text input containing the instructions in hex format.
///
/// Expects one instruction per line, and lines may begin with `//` to denote a comment.
///
/// # Examples
///
/// ```
/// use ibcm::Simulator;
///
/// let program = "// A comment
/// 1000
///     1800  // Indentation is supported
/// 0000";
/// let sim = Simulator::from_hex(program.as_bytes()).unwrap();
///
/// assert_eq!(&[0x1000, 0x1800, 0x0000], &sim.memory()[..3]);
/// ```
Load the simulator from text input containing the instructions in hex format.
Expects one instruction per line, and lines may begin with `//` to denote a comment.
Load the simulator from text input containing the instructions in hex format . Expects one instruction per line and lines may begin with ` // ` to denote a comment .
pub fn from_hex<R: Read>(input: R) -> Result<Self> {
        let mut data = [0u16; 4096];
        let mut i = 0;
        let br = BufReader::new(input);
        for l in br.lines() {
            let l = l.chain_err(|| ErrorKind::Io("could not read from hex input".into()))?;
            let l = l.trim();
            if l.is_empty() || l.starts_with("//") {
                continue;
            }
            // Try to read a word
            let word = u16::from_str_radix(&l[..4], 16).chain_err(|| {
                    ErrorKind::UserInput(format!("expected hexadecimal word at start of line: \
                                                  '{}'",
                                                 l))
                })?;
            if i >= data.len() {
                return Err(ErrorKind::ProgramTooLong.into());
            }
            data[i] = word;
            i += 1;
        }
        Ok(Simulator::from_memory(data, i))
    }
pub fn from_hex < R : Read > ( input : R ) -> Result < Self > { let mut data = [ 0u16 ; 4096 ] ; let mut i = 0 ; let br = BufReader :: new ( input ) ; for l in br . lines ( ) { let l = l . chain_err ( | | ErrorKind :: Io ( " " . into ( ) ) ) ? ; let l = l . trim ( ) ; if l . is_empty ( ) || l . starts_with ( " " ) { continue ; } // Try to read a word let word = u16 :: from_str_radix ( & l [ .. 4 ] , 16 ) . chain_err ( | | { ErrorKind :: UserInput ( format ! ( " \
 " l ) ) } ) ? ; if i >= data . len ( ) { return Err ( ErrorKind :: ProgramTooLong . into ( ) ) ; } data [ i ] = word ; i += 1 ; } Ok ( Simulator :: from_memory ( data , i ) ) }
Load the simulator from text input containing the instructions in hex format.
Load the simulator from text input containing the instructions in hex format .
input
R
examples
```
use ibcm::Simulator.

let program = "// A comment
1000
1800  // Indentation is supported
0000";
let sim = Simulator::from_hex(program.as_bytes()).unwrap().


` ` ` use ibcm :: Simulator . let program = " // A comment 1000 1800 // Indentation is supported 0000 " ; let sim = Simulator :: from_hex ( program . as_bytes () ) . unwrap () .