Programming Pearls -- Column 1: Sorting unique numbers with bitfield I've implemented a simple program to sort an input of unique  numbers given as decimals on a separate line.  The idea is, since all numbers are unique, to use a (long) bitfield where a 1 on index n represents that the number n is in the sorted list.  The algorithm thus consists of these phases (as described in the book):
/* phase 1: initialize set to empty */
    for i = [0, n)
        bit[i] = 0
/* phase 2: insert present elements into the set */
    for each i in the input file
        bit[i] = 1
/* phase 3: write sorted output */
    for i = [0, n)
        if bit[i] == 1
            write i on the output file

In order to (re-)freshen my Rust, I chose to implement this in Rust, to be an efficient replacement for sort(1) when given the -n option, assuming unique input.  Thus the program can be called as:
$ bitfield # sorts stdin, writes to stdout
$ bitfield foo # sorts foo, writes to stdout
$ bitfield foo - bar # sorts foo, stdin, bar, writes to stdout

As with the exercise, I assume n (MAXNUM) to be 10,000,000:
use std::io::*;
use std::fs::File;
use std::env;

const MAXNUM: usize = 10_000_000;
const _MAXLINES: usize = 1_000_000;

fn fill(src: impl BufRead, bitfield: &amp;mut[u8; MAXNUM &gt;&gt; 3]) -&gt; Result&lt;()&gt; {
    for line in src.lines() {
        let num = line?.parse::&lt;usize&gt;().unwrap();
        if num &gt; MAXNUM {
            return Err(Error::new(ErrorKind::Other, &quot;number too large!&quot;));
        }

        bitfield[num &gt;&gt; 3] |= 1 &lt;&lt; (num &amp; 0b111);
    }

    return Ok(());
}

fn print_sorted(bitfield: &amp;[u8; MAXNUM &gt;&gt; 3], dest: impl Write) -&gt; Result&lt;()&gt; {
    let mut dest = BufWriter::new(dest);

    for (i, byte) in bitfield.iter().enumerate() {
        for bit in 0..=0b111 {
            if byte &amp; (1 &lt;&lt; bit) != 0 {
                write!(&amp;mut dest, &quot;{}\n&quot;, (i &lt;&lt; 3) | bit)?;
            }
        }
    }

    return Ok(());
}

fn main() -&gt; Result&lt;()&gt; {
    let mut bitfield: [u8; MAXNUM &gt;&gt; 3] = [0; MAXNUM &gt;&gt; 3];

    let args: Vec&lt;_&gt; = env::args().skip(1).collect();
    if args.is_empty() {
        fill(stdin().lock(), &amp;mut bitfield)?;
    }

    for arg in args {
        if arg == &quot;-&quot; {
            fill(stdin().lock(), &amp;mut bitfield)?;
        } else {
            let f = match File::open(&amp;arg) {
                Err(e) =&gt; {
                    eprintln!(&quot;{}: {}&quot;, &amp;arg, e);
                    continue;
                }
                Ok(f) =&gt; BufReader::new(f),
            };
            fill(f, &amp;mut bitfield)?;
        }
    }
    print_sorted(&amp;bitfield, stdout())?;

    return Ok(());
}

To test, I used GNU/shuf(1), time(1), and cmp(1):
$ shuf -i 1-10000000 -n 1000000 &gt; foo
$ time ./target/release/bitsort foo &gt; bar
0.19s user 0.03s system 97% cpu 0.221 total
$ time sort -n foo &gt; bar2
1.56s user 0.06s system 291% cpu 0.556 total
$ cmp bar bar2

Ideas?
use declarations
use std::env;
use std::fs::File;
use std::io::*;

That's a sneaky way to import io::{Error, Result}.  For the sake of
readability, it may be beneficial to spell out io:: each time.  Also
see the Error handling section below.
use declarations can be condensed.  For example:
use std::{env, fs::File, io};

Allocation
let args: Vec&lt;_&gt; = env::args().skip(1).collect();

This is an unnecessary allocation.  The main function can be
rewritten in terms of iterators using peekable:
fn main() -&gt; Result&lt;()&gt; {
    // ...

    let mut args = env::args().skip(1).peekable();

    if args.peek().is_none() {
        // read from stdin
    }

    for arg in args {
        // handle arg
    }

    // ...
}

Error handling
Instead of unwrapping the result of parse, you can propagate the
error.
For a larger program, I would suggest using the anyhow crate
for error handling, which reduces a lot of boilerplate.
Miscellaneous
Don't write return Ok(()); at the end of a function — just use
Ok(()).
I think you meant &gt;= here: if num &gt; MAXNUM.
In print_sorted, you wrap the writer in a BufWriter.  What if the
writer is already buffered?  I would leave the decision to the caller.
You can use let mut bitfield = [0_u8; MAXNUM &gt;&gt; 3]; for less
duplication.
Using a crate like bit-set might be good for readability.